4 Lecture
CS304
Midterm & Final Term Short Notes
CONCEPTS RELATED WITH INHERITANCE
Inheritance is a fundamental concept in object-oriented programming that allows new classes to be based on existing classes, inheriting their properties and behaviors. Inheritance creates a hierarchy of classes, with more specific subclasses inh
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
In object-oriented programming, what is inheritance? a) A way to create new objects based on existing ones b) A way to create new classes based on existing ones c) A way to create new methods based on existing ones d) A way to create new properties based on existing ones Answer: b) A way to create new classes based on existing ones What is a superclass in inheritance? a) A class that inherits from another class b) A class that is inherited by another class c) A class that has no parent class d) A class that is created from scratch Answer: b) A class that is inherited by another class What is a subclass in inheritance? a) A class that inherits from another class b) A class that is inherited by another class c) A class that has no parent class d) A class that is created from scratch Answer: a) A class that inherits from another class What is the purpose of inheritance in object-oriented programming? a) To create new objects b) To reduce code redundancy c) To create new methods d) To create new properties Answer: b) To reduce code redundancy Which of the following keywords is used to denote inheritance in Java? a) extends b) implements c) interface d) abstract Answer: a) extends Which type of inheritance allows a subclass to inherit from multiple parent classes? a) Single inheritance b) Multiple inheritance c) Multilevel inheritance d) Hierarchical inheritance Answer: b) Multiple inheritance Inheritance promotes which principle of object-oriented programming? a) Encapsulation b) Polymorphism c) Abstraction d) All of the above Answer: d) All of the above Which access modifier in Java allows a subclass to access a protected member of its parent class? a) public b) private c) protected d) default Answer: c) protected What is method overriding in inheritance? a) Creating a new method in the subclass with the same name as a method in the parent class b) Creating a new method in the parent class with the same name as a method in the subclass c) Renaming a method in the subclass to match a method in the parent class d) Hiding a method in the parent class from the subclass Answer: a) Creating a new method in the subclass with the same name as a method in the parent class What is method overloading in inheritance? a) Creating a new method in the subclass with the same name as a method in the parent class b) Creating a new method in the parent class with the same name as a method in the subclass c) Renaming a method in the subclass to match a method in the parent class d) Creating a new method in the subclass with the same name but different parameters as a method in the parent class Answer: d) Creating a new method in the subclass with the same name but different parameters as a method in the parent class
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is inheritance in object-oriented programming? Answer: Inheritance is a mechanism that allows new classes to be based on existing classes, inheriting their properties and methods. What is the difference between a superclass and a subclass? Answer: A superclass is a class that is inherited by another class, while a subclass is a class that inherits from another class. How does inheritance promote code reuse? Answer: Inheritance promotes code reuse by allowing a subclass to inherit properties and methods from its parent class, reducing the need to write duplicate code. What is method overriding in inheritance? Answer: Method overriding is when a subclass provides its own implementation of a method that is already defined in its parent class. What is the difference between method overriding and method overloading? Answer: Method overriding is when a subclass provides its own implementation of a method that is already defined in its parent class, while method overloading is when a class has multiple methods with the same name but different parameters. What is the purpose of access modifiers in inheritance? Answer: Access modifiers in inheritance control the visibility of inherited members, allowing subclasses to access or modify inherited properties and methods according to their accessibility. What is polymorphism in inheritance? Answer: Polymorphism in inheritance is the ability of objects of different classes to be treated as if they are of the same type, allowing them to be used interchangeably. What is the difference between single and multiple inheritance? Answer: Single inheritance is when a subclass inherits from only one parent class, while multiple inheritance is when a subclass inherits from multiple parent classes. What are the advantages of using inheritance in object-oriented programming? Answer: Advantages of using inheritance include reduced code redundancy, easier maintenance, increased modularity, and the ability to achieve polymorphism. What are some potential drawbacks of using multiple inheritance? Answer: Potential drawbacks of using multiple inheritance include increased complexity and ambiguity, the possibility of naming conflicts, and difficulty in maintaining and understanding the code.