22 Lecture
CS304
Midterm & Final Term Short Notes
PRACTICAL IMPLEMENTATION OF INHERITANCE IN C
Inheritance is a powerful concept in object-oriented programming that allows the creation of new classes based on existing classes. In C, inheritance can be implemented using structures and function pointers. Inheritance allows the reuse of code
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- Inheritance in C can be implemented using:
a) Structures and function pointers
b) Classes and objects
c) Inheritance keyword
d) None of the above
Answer: a) Structures and function pointers
Which of the following is not a type of inheritance?
a) Single inheritance
b) Multiple inheritance
c) Hierarchical inheritance
d) Parallel inheritance
Answer: d) Parallel inheritance
The derived class inherits:
a) All the properties and methods of the base class
b) Only the properties of the base class
c) Only the methods of the base class
d) None of the above
Answer: a) All the properties and methods of the base class
What is the syntax to define a derived structure in C?
a) struct Derived : Base {}
b) struct Derived extends Base {}
c) struct Derived : public Base {}
d) struct Derived : private Base {}
Answer: c) struct Derived : public Base {}
Inheritance is used to:
a) Achieve code reusability
b) Encapsulate data
c) Control access to data
d) None of the above
Answer: a) Achieve code reusability
Which type of inheritance allows a derived class to inherit from multiple base classes?
a) Single inheritance
b) Multiple inheritance
c) Hierarchical inheritance
d) Hybrid inheritance
Answer: b) Multiple inheritance
Which keyword is used to call the constructor of the base class from the derived class constructor?
a) super
b) base
c) this
d) parent
Answer: b) base
Which type of inheritance involves creating a new class that inherits from a base class, and then creating another class that inherits from the new class?
a) Single inheritance
b) Multiple inheritance
c) Hierarchical inheritance
d) Hybrid inheritance
Answer: c) Hierarchical inheritance
Which of the following is not a benefit of inheritance?
a) Code reusability
b) Improved maintainability
c) Reduced coupling
d) Increased code complexity
Answer: d) Increased code complexity
Which of the following is an example of polymorphism?
a) Overriding a method in a derived class
b) Calling a method from the base class
c) Inheriting properties from a base class
d) None of the above
Answer: a) Overriding a method in a derived class
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
How is inheritance implemented in C? Answer: Inheritance in C is implemented using structures and function pointers. What is the difference between a base class and a derived class? Answer: A base class is a class from which other classes are derived, while a derived class is a class that inherits properties and methods from the base class. How is a derived structure defined in C? Answer: A derived structure in C is defined using the syntax "struct Derived : public Base {}". What is the purpose of inheritance? Answer: The purpose of inheritance is to achieve code reusability and simplify the creation of new classes with similar functionality to existing classes. What is multiple inheritance? Answer: Multiple inheritance is a type of inheritance in which a derived class can inherit from multiple base classes. How do you call the constructor of the base class from the derived class constructor? Answer: The constructor of the base class can be called from the derived class constructor using the "base" keyword. What is hierarchical inheritance? Answer: Hierarchical inheritance is a type of inheritance in which a new class is created that inherits from a base class, and then another class is created that inherits from the new class. What are the benefits of inheritance? Answer: The benefits of inheritance include code reusability, improved maintainability, and reduced coupling. What is function overriding in inheritance? Answer: Function overriding in inheritance is when a derived class defines a method with the same name and signature as a method in the base class, effectively replacing the method in the base class. How does inheritance relate to polymorphism? Answer: Inheritance and polymorphism are related in that polymorphism is achieved through inheritance, specifically through the use of function overriding.