← 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 →- Q1. What is true about a constructor?
- Q2. What does this print? (code)
- Q3. Why is this constructor buggy? Student(String name) { name = name; }
- Q4. Which access modifier makes a field visible ONLY inside its own class?
- Q5. Why can't a static method use an instance field directly?
- Q6. What does this print? (code)
- Q7. A class has only the constructor Student(String name). What does new Student() do?
- Q8. What does this print? (code)
- Q9. What is the main benefit of private fields with public methods (encapsulation)?
- Q10. A field is declared protected. Where can it be used?