WorksheetsOOP Concepts: Inheritance and More
Total questions: 20
Worksheet time: 10mins
What type of inheritance allows a class to inherit from multiple classes?
Single inheritance
Multilevel inheritance
Multiple inheritance
Hierarchical inheritance
Which access modifier allows a class member to be accessible only within its own class?
private
internal
public
protected
What is the main purpose of constructor overloading?
To simplify the constructor parameters for all objects.
To enforce a single way of object initialization.
To limit the number of objects created.
The main purpose of constructor overloading is to provide flexibility in object creation.
In method overriding, which method is called from the subclass?
The original method in the interface is called.
The method is not called at all.
The overridden method in the subclass is called.
The method in the superclass is called.
What is polymorphism in object-oriented programming?
Polymorphism refers to the ability of a single class to inherit from multiple parent classes.
Polymorphism is the ability of different classes to be treated as instances of the same class through a common interface, enabling method overriding and dynamic method binding.
Polymorphism is the process of creating multiple classes with identical methods and properties.
Polymorphism is the technique of combining different data types into a single class structure.
Which type of inheritance is represented by a single base class and multiple derived classes?
Multiple Inheritance
Hierarchical Inheritance
Single Inheritance
Multilevel Inheritance
What access modifier allows a class member to be accessible to classes in the same package?
default (package-private)
public
private
protected
What is the result of calling a constructor with different parameters?
Different instances or states of the object are created.
Only one instance can be created regardless of parameters.
The constructor will always return the same object.
Parameters have no effect on the object's state.
In method overriding, what keyword is used to refer to the superclass method?
ancestor
super
parent
base
What is the main benefit of encapsulation in OOP?
The main benefit of encapsulation is faster execution speed.
Encapsulation allows for unlimited data access and sharing.
The main benefit of encapsulation is data protection and integrity.
Encapsulation enhances code readability and simplicity.
Which type of polymorphism is achieved at compile time?
Compile-time polymorphism
Static type polymorphism
Dynamic polymorphism
Run-time polymorphism
What is the purpose of the 'super' keyword in Java?
The 'super' keyword is used to create new classes.
The 'super' keyword is used to define interfaces.
The 'super' keyword is used to implement multiple inheritance.
The 'super' keyword is used to access superclass methods and constructors.
Which access modifier allows a class member to be accessible from any other class?
private
public
internal
protected
What happens if a subclass does not override a method from its superclass?
The subclass cannot access the superclass method.
The subclass inherits the method from its superclass.
The superclass method is deleted from the subclass.
The subclass must implement the method itself.
What is the difference between method overloading and method overriding?
Method overloading is for the same method name with different parameters; method overriding is for redefining a superclass method in a subclass.
Method overloading is about changing return types; method overriding is for private methods.
Method overloading requires inheritance; method overriding does not involve parameters.
Method overloading changes the method name; method overriding is for static methods only.
Which type of inheritance is not allowed in most programming languages?
Hybrid inheritance
Multilevel inheritance
Single inheritance
Multiple inheritance
What is the effect of using private access modifier on a class member?
The member is accessible to all subclasses.
The member can be accessed from any package.
The member is accessible only to the public interface.
The member is accessible only within the defining class.
How can you achieve method overloading in a class?
Define multiple methods with the same name but different parameters.
Implement a method with a fixed number of parameters.
Create a single method with multiple return types.
Use different class names for each method.
What is the significance of the 'this' keyword in constructors?
The 'this' keyword is a way to declare global variables in JavaScript.
The 'this' keyword is used to define static methods in classes.
The 'this' keyword refers to the parent class in inheritance.
The 'this' keyword is significant in constructors as it represents the current instance of the object, allowing access to its properties and methods.
What is the main characteristic of multiple inheritance?
The ability of a class to inherit from a single parent class.
The restriction of a class to only one type of inheritance.
The process of combining multiple classes into one class.
The ability of a class to inherit from multiple parent classes.
