← Back to Subject
OOP Using Java • MCQ • Inheritance, Interfaces and Packages
Most Important 30 Objective Question - Inheritance, Interface and Packages
Q1. Which OOP feature allows one class to inherit properties of another class?
A) Encapsulation
B) Inheritance
C) Polymorphism
D) Abstraction

Answer: B) Inheritance
Explanation:Inheritance allows one class (child class) to acquire properties and methods of another class (parent class).

Q2. The class which is inherited is called:
A) Child Class
B) Subclass
C) Parent Class
D) Derived Class

Answer: C) Parent Class
Explanation:The class whose properties are inherited is called the parent class or superclass.

Q3. The class which inherits another class is called:
A) Superclass
B) Parent Class
C) Subclass
D) Main Class

Answer: C) Subclass
Explanation:The class that inherits features from another class is called subclass or child class.

Q4. Which keyword is used for inheritance in Java?
A) inherit
B) extends
C) implements
D) super

Answer: B) extends
Explanation:The keyword extends is used to inherit a class.
Example:
class B extends A
{
}

Q5. Which keyword is used to call parent class constructor?
A) this
B) final
C) super
D) static

Answer: C) super
Explanation:
The super keyword is used to call parent class constructor and methods.

Q6. Java supports which type of inheritance through classes?
A) Multiple Inheritance
B) Hybrid Inheritance
C) Single Inheritance
D) Multiple + Hybrid

Answer: C) Single Inheritance
Explanation:Java supports single inheritance through classes. Multiple inheritance is achieved using interfaces.

Q7. Which keyword is used to stop inheritance?
A) static
B) final
C) private
D) protected

Answer: B) final
Explanation:A final class cannot be inherited.
Example:
final class A
{
}

Q8. Which method is used to achieve runtime polymorphism?
A) Method Overloading
B) Method Overriding
C) Constructor Overloading
D) Static Binding

Answer: B) Method Overriding
Explanation:Method overriding provides runtime polymorphism.

Q9. Which method is used to achieve compile-time polymorphism?
A) Method Overriding
B) Method Overloading
C) Inheritance
D) Interface

Answer: B) Method Overloading
Explanation:Method overloading provides compile-time polymorphism.

Q10. Which keyword is used to define an abstract class?
A) final
B) static
C) abstract
D) interface

Answer: C) abstract
Explanation:The abstract keyword is used to declare abstract classes and methods.

Q11. An abstract method must be declared in:
A) Final Class
B) Abstract Class
C) String Class
D) Package

Answer: B) Abstract Class
Explanation:Abstract methods must be inside an abstract class.

Q12. Can we create an object of abstract class?
A) Yes
B) No
C) Sometimes
D) Only in main()

Answer: B) No
Explanation:Abstract classes are incomplete, so objects cannot be created directly.

Q13. Which keyword is used to define an interface?
A) class
B) abstract
C) interface
D) implements

Answer: C) interface
Explanation:The interface keyword is used to declare an interface.

Q14. Which keyword is used to implement an interface?
A) extends
B) implement
C) implements
D) inherit

Answer: C) implements
Explanation:A class uses the implements keyword to use an interface.
Example:
class A implements Printable
{
}

Q15. Interface mainly supports:
A) Multiple Inheritance
B) Single Inheritance
C) Encapsulation
D) Constructor Overloading

Answer: A) Multiple Inheritance
Explanation:Java uses interfaces to achieve multiple inheritance.

Q16. Which class is the parent of all classes in Java?
A) String
B) Main
C) Object
D) System

Answer: C) Object
Explanation:The Object class is the root class in Java. Every class directly or indirectly inherits from it.

Q17. Which method belongs to Object class?
A) toString()
B) main()
C) run()
D) start()

Answer: A) toString()
Explanation:Methods like toString(), equals(), hashCode() belong to the Object class.

Q18. Which binding happens at runtime?
A) Static Binding
B) Dynamic Binding
C) Early Binding
D) Compile Binding

Answer: B) Dynamic Binding
Explanation:Dynamic binding happens during runtime and is used in method overriding.

Q19. Which binding happens at compile time?
A) Dynamic Binding
B) Runtime Binding
C) Static Binding
D) Late Binding

Answer: C) Static Binding
Explanation:Static binding happens at compile time and is used in method overloading.

Q20. Which keyword is used to access parent class members?
A) this
B) static
C) super
D) final

Answer: C) super
Explanation:The super keyword is used to access parent class variables, methods, and constructors.

Q21. Which class cannot be inherited?
A) Abstract Class
B) Final Class
C) Parent Class
D) Child Class

Answer: B) Final Class
Explanation:A final class cannot be extended by another class.

Q22. Which method cannot be overridden?
A) Static Method
B) Final Method
C) Public Method
D) Protected Method

Answer: B) Final Method
Explanation:A method declared with final cannot be overridden.

Q23. Which of the following is true for interface methods (traditional Java concept)?
A) They are private
B) They are public and abstract
C) They are protected
D) They are final

Answer: B) They are public and abstract
Explanation:By default, interface methods are public and abstract.

Q24. Which keyword is used to create a package?
A) import
B) package
C) class
D) extends

Answer: B) package
Explanation:The package keyword is used to define a package.
Example:
package mypack;

Q25. Which keyword is used to use another package?
A) include
B) package
C) import
D) extends

Answer: C) import
Explanation:The import keyword is used to access classes from another package.

Q26. CLASSPATH is used for:
A) Finding Java classes
B) Creating objects
C) Compiling methods
D) Running threads

Answer: A) Finding Java classes
Explanation:CLASSPATH tells JVM and compiler where to find user-defined classes and packages.

Q27. Which is better for complete abstraction?
A) Class
B) Interface
C) Constructor
D) Method

Answer: B) Interface
Explanation:Interface provides complete abstraction because it contains abstract methods (traditional concept).

Q28. Abstract class can have:
A) Only abstract methods
B) Only constructors
C) Both abstract and non-abstract methods
D) Only static methods

Answer: C) Both abstract and non-abstract methods
Explanation:Abstract classes can contain both types of methods.

Q29. Java achieves multiple inheritance using:
A) Class
B) Constructor
C) Interface
D) Package

Answer: C) Interface
Explanation:Java does not support multiple inheritance using classes, but supports it using interfaces.

Q30. Which of the following is not inherited from Object class?
A) toString()
B) equals()
C) hashCode()
D) main()

Answer: D) main()
Explanation:main() is not inherited from Object class. It is the entry point of Java program.
Google AdSense Ad Placement Here 📢