- Type
- Final term past paper
- Course
- CS304 Object Oriented Programming
- Size
- PDF 847 KB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extensionSign in with the extension for 30 a day.
Preview text
Text from pages 1, 2, 3 of 52. Download the file for all 52 pages.
CS304 Object Oriented Programming Lecture Wise Questions and Answers For Final Term Exam Preparation By Virtualians Social Network
Lecture 22 Short notes :
There‟s 3 type of inheritance in C++
1 Public 2 Private 3 Protected
Public inheritance implements „is a kind of‟ relationship.
In public inheritance , public members of the base class become public members of the derived class whereas private parts of the base class can not be accessed by derived class.
So derived class‟s interface comprises of 2 parts :1st part is derived class‟s own public member functions and the 2nd and the public member functions of the base class.
Whenever a derived class‟s object is to be created, the constructor of the base class would be executed first. First, Base class constructor will initialize the base class object and then derived class constructor will initialize the derived class object. From derived class constructor, a base class constructor can also be called explicitly. Base class Constructor Is always called first in either case.
Lecture 23:
Protected access specifier:
If a member is given „protected access specification‟ , such member can not be accessed from outside the class. However, a publicly derived class can access such protected members of the base class.
Derived object is a kind of base object. The base class pointer can point towards an object of derived class and vice versa.
cout << pPtr-> GetRollNo(); //Error because pPtr is a pointer to the person class and not the student class. And in person class, we have just assigned a name and not the RollNo(), which belongs to the student class. So we can not assume that a person is also a student, doctor etc. In other words, pPtr‟s static type is Person, and in Person class, we have not declared RollNo(). So, Access is governed by static type of the object/identity through which a member is being tried to be accessed. Same rule applies in case of Reference (&) as well.
Static Type: The type that is used to declare a reference or pointer is called its static type.
Q. IS-A and HAS-A Relationship
Ans
IS-A means you can have a class that "is a" something. Like a student "IS-A" person. This is used to describe one object being a subclass of another.
Sometimes there isn't a IS-A relationship between two classes, but a "HAS-A" is more appropriate. Example, a chair "HAS-A" leg. Or several. This is called aggregation, as opposed to inheritance.
Is a = Special kind of e.g. Car is special kind of Vehicle.
Has a = It physically has something, e.g Car has an engine.
- A House is a Building (inheritance);
- A House has a Room (composition);
- A House has an occupant (aggregation).
Q. Default constructor
Ans
In Default constructor all the parameters have default values. If no constructors are available for a class, the compiler implicitly creates a default parameterless constructor without a constructor initializer and a null body.
Q. Static Type Ans
The type that is used to declare a reference or pointer is called its static type e.g.
- In Person * pPtr = 0;
The static type of pPtr is Person * (Person pointer).
- Student s;
The static type of s is Student.
Q.Use of Protected key word:
Ans
The protected keyword specifies access to class members in the member-list up to the next access specifier (public or private) or the end of the class definition. Class members declared as protected can be used only by the following:
Member functions of the class that originally declared these members. Friends of the class that originally declared these members. Classes derived with public or protected access from the class that originally declared these members. Direct privately derived classes that also have private access to protected members.
Lec 24:
Lec 24: If we have to initialize a publicly derived class object to some other object through calling copy constructor, if there‟s no copy constructor in derived and base class, the compiler will create them automatically. First base class‟s part is copied and later on the derived one‟s. If user has written the copy constructor then it is necessary to call the base class‟s copy constructor from derived class‟s copy constructor. Base class‟s copy constructor will called from the member initialize of the derived class’s copy constructor.
Q. What is the purpose of following keyword in C++? how it is employed, kindly explain with examples:-
Related CS304 files
All CS304 files →- CS304 Final Term MCQs Set 2 by VU Topper RM Final term PDF 634 KB
- CS304 Final Term Past Papers Final term PDF 146 KB
- CS304 Final Term MCQs by Waqar Siddhu Final term PDF 36.2 MB
- CS304 Final Term Solved MCQs Set 2 by Junaid Final term PDF 2.3 MB
- CS304 Official Handouts Official handout PDF 2.8 MB Free
- CS304 Quiz 2 by Smile Quiz PDF 467 KB
Get more out of VUBuddy, for free
- Unlimited downloads
- The explanation behind every MCQ answer
- Study offline on slow data
- 30 downloads a day instead of 3
- Sign in and buy Pro Semester here
One Pro Semester membership works in both the extension and the app.