Scope and Access

AP Computer Science A· difficulty 2/5

public class Card {
    public String suit;
    private int rank;
    public Card(String s, int r) { suit = s; rank = r; }
}
// ...
Card c = new Card("H", 7);
System.out.println(c.suit);

What is printed?

  • A

    H

    check_circle
  • B

    7

  • C

    Compile-time error

  • D

    null

Explanation

suit is public, so it can be accessed from outside the class. It was set to "H".

Want 10 more like this — adaptive to your weak spots?

Related questions