🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Java Classes and Objects: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What is true about a constructor?
  2. Q2. What does this print? (code)
  3. Q3. Why is this constructor buggy? Student(String name) { name = name; }
  4. Q4. Which access modifier makes a field visible ONLY inside its own class?
  5. Q5. Why can't a static method use an instance field directly?
  6. Q6. What does this print? (code)
  7. Q7. A class has only the constructor Student(String name). What does new Student() do?
  8. Q8. What does this print? (code)
  9. Q9. What is the main benefit of private fields with public methods (encapsulation)?
  10. Q10. A field is declared protected. Where can it be used?