1.
Which of the following concepts in Object-Oriented Programming allows a subclass to inherit methods and properties from a superclass while also providing its own specific implementation?
Correct Answer
C. Inheritance
Explanation
Inheritance is a key concept in Object-Oriented Programming that allows a subclass to inherit methods and properties from a superclass. This enables code reuse and the creation of hierarchical relationships between classes. While the subclass inherits common characteristics, it can also provide its own specific implementation or override methods from the superclass. Encapsulation, polymorphism, and abstraction are also core OOP concepts, but they serve different purposes.
2.
To call a base class constructor in a derived class, it is needed to call the base class initializer.
Correct Answer
A. True
Explanation
In most object-oriented programming languages, when you create a derived class (subclass), and you want to call the constructor of its base class (superclass), you typically need to invoke the base class constructor using the base class initializer. This is usually done using the super() keyword in languages like Java or the base() keyword in languages like C#.
3.
Can objects of abstract classes be instantiated?
Correct Answer
B. No
Explanation
Objects of abstract classes cannot be instantiated because abstract classes are incomplete and cannot be fully implemented. They are designed to be extended by subclasses, which provide the missing implementation details. Therefore, attempting to create an object of an abstract class would result in a compilation error.
4.
The process by which one object can acquire the properties of another object:
Correct Answer
B. Inheritance
Explanation
Inheritance is the process by which one object can acquire the properties of another object. It allows a class to inherit the attributes and methods of another class, known as the parent or base class. This promotes code reusability and helps in creating a hierarchical relationship between classes. The child class can access and use the methods and variables of the parent class, and also add its own unique features. Inheritance is an essential concept in object-oriented programming and facilitates the organization and structuring of code.
5.
Constructors are used to:
Correct Answer
C. Initialize a newly created object.
Explanation
Constructors are special methods in object-oriented programming that are used to initialize a newly created object. They are called automatically when an object is created and are responsible for setting initial values for the object's attributes. By initializing the object, constructors ensure that it is in a valid and usable state from the moment it is created. Constructors are not used to build a user interface, free memory, or create a sub-class.
6.
An object that has more than one form is referred to as:
Correct Answer
D. PolymorpHism
Explanation
Polymorphism refers to the ability of an object to take on different forms or has different behaviors. In object-oriented programming, polymorphism allows objects of different classes to be treated as objects of a common superclass. This means that a single method can be used to perform different actions depending on the type of object it is called on. Polymorphism promotes code reusability and flexibility, as it allows for the creation of generic code that can be applied to multiple objects with different forms or behaviors.
7.
Information Hiding can also be termed as:
Correct Answer
A. Data hiding
Explanation
Information hiding can also be termed as Data hiding. It refers to the practice of restricting access to certain details of an object and only revealing what is necessary for the functioning of the object. This concept is often associated with encapsulation, where the implementation details of an object are hidden from the outside world, and only the necessary interfaces are exposed. However, information hiding specifically emphasizes the concealment of data details, ensuring that the internal representation of data is not directly accessible from outside the object.
8.
Pick the term that relates to polymorphism:
Correct Answer
A. Dynamic binding
Explanation
Dynamic binding refers to the process of determining the specific implementation of a method or function at runtime, based on the actual type of the object or variable it is being called on. This allows for the implementation to be selected dynamically, enabling polymorphism. Polymorphism is the ability of an object to take on many forms, where different objects can be treated as instances of a common superclass, and methods can be called on them based on their individual implementations. Therefore, dynamic binding is closely related to polymorphism as it allows for the flexibility and versatility of objects in object-oriented programming.
9.
Main method can be overridden:
Correct Answer
B. False
Explanation
The main method in Java is a special method that serves as the entry point for a Java program. It cannot be overridden because it is a static method and cannot be inherited. The main method is declared with a specific signature and is called by the Java Virtual Machine (JVM) to execute the program. Therefore, it is not possible to override the main method in Java.
10.
The keyword that is used to access the method or member variables from the superclass:
Correct Answer
A. Super
Explanation
The keyword "super" is used to access the method or member variables from the superclass. It is used when a subclass wants to refer to a method or variable that it has inherited from its superclass. By using the "super" keyword, the subclass can call the superclass's version of the method or access its variables. This allows for code reuse and helps in implementing inheritance in object-oriented programming.
11.
What modifiers are allowed for methods in an Interface?
(choose one or more answers)
Correct Answer(s)
A. Public
C. Abstract
Explanation
Methods in an interface can only have the "public" and "abstract" modifiers. The "public" modifier allows the method to be accessed from other classes, while the "abstract" modifier indicates that the method does not have a body and must be implemented by any class that implements the interface. The "private" modifier is not allowed because it restricts access to the method and would contradict the purpose of an interface, which is to define a contract for implementing classes.
12.
When sub class declares a method that has the same type of arguments as a method declared by one of its superclasses, it is termed as:
Correct Answer
A. Method overriding
Explanation
Method overriding occurs when a subclass declares a method that has the same type of arguments as a method declared by one of its superclasses. This allows the subclass to provide its own implementation of the method, which overrides the implementation in the superclass. This is a fundamental concept in object-oriented programming, as it allows for polymorphism and the ability to have different behavior for the same method in different subclasses.