W3Reference.com
Toggle Menu
Home
Online Rust Compiler
Tutorials
Python Tutorial
Java Tutorial
Rust Tutorial
TypeScript Tutorial
ReactJS Tutorial
HTML & CSS Basics
Docker Containers Guide
Kubernetes Tutorial
Software Design Patterns
Blog
All Posts
Object-Oriented Programming in Java
Test your knowledge of classes,inheritance,and polymorphism.
1. Which of the following is NOT one of the four main pillars of Object-Oriented Programming?
Encapsulation
Inheritance
Polymorphism
Iteration
2. In Java, a class can extend multiple classes.
True
False
3. What keyword is used to define a subclass in Java?
extends
implements
super
this
4. What keyword is used to prevent a method from being overridden in Java?
5. Which of the following are access modifiers in Java?
public
private
protected
static
package-private (default)
6. What is the default value of a boolean instance variable in Java?
true
false
null
0
7. An abstract class can contain both abstract and concrete methods.
True
False
8. What is the term for a special method in Java that shares the same name as its class and is used to initialize objects?
9. Which statements about interfaces in Java are true (select all that apply)?
Interfaces can contain method implementations (since Java 8)
Interfaces can have instance variables
A class can implement multiple interfaces
Interfaces are declared with the 'interface' keyword
10. What is polymorphism in OOP?
Hiding the internal state of an object
A class acquiring properties of another class
An object taking multiple forms through inheritance/implementation
Defining methods with the same name but different parameters
11. A static method in Java can directly access non-static instance variables.
True
False
12. Which keyword is used to refer to the current instance of a class in Java?
this
super
self
current
13. What keyword is used to declare a class that cannot be subclassed?
14. Which of the following are examples of encapsulation in Java (select all that apply)?
Declaring instance variables as private
Providing public getter and setter methods
Using the 'static' keyword for methods
Making a class 'final'
15. What happens if a Java class defines a main method with a return type of 'int'?
Compile-time error
Runtime error
The program runs but exits with code 0
The return type is ignored
16. What is method overloading?
A subclass method with the same name as a superclass method
Multiple methods in a class with the same name but different parameters
A method that cannot be overridden
A method with no parameters
17. Which keyword is used to call a superclass constructor from a subclass constructor?
super()
this()
extends
super
18. Which of the following are true about abstract methods (select all that apply)?
They have a method body
They must be declared in an abstract class or interface
They must be overridden by concrete subclasses
They are declared with the 'abstract' keyword
19. What is the purpose of the 'this' keyword in Java?
To refer to the superclass instance
To refer to the current class instance
To declare a static variable
To exit a method
20. Which OOP principle focuses on hiding implementation details and exposing only necessary features?
Abstraction
Inheritance
Polymorphism
Encapsulation
Reset
Answered 0 of 0 — 0 correct