Skills101
← All practice quizzes

Quiz: Java Classes and Objects

5 questionsNo time limitPass: 60%+10 XP on first pass

Model real things with classes. Fields, constructors (default, parameterised, chaining), the this keyword, static members, getters/setters and toString().

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What is true about a constructor?

  2. Question 2

    What does this print?

    class A {
        static int count = 0;
        A() { count++; }
    }
    public class Main {
        public static void main(String[] args) {
            new A(); new A(); new A();
            System.out.println(A.count);
        }
    }
    
  3. Question 3

    Why is this constructor buggy? Student(String name) { name = name; }

  4. Question 4

    Which access modifier makes a field visible ONLY inside its own class?

  5. Question 5

    Why can't a static method use an instance field directly?