Practice Questions of CPP - Subclass
Practice Questions of CPP - Subclass
Practice questions
on Subclass
Level 1
Level 1
1.
Create a class with a function that
prints "This is parent class" and its
subclass with another function that
prints "This is child class". Now,
create an object for each class and
call
1 - function of the parent class by the
object of the parent class
2 - function of the child class by the
object of the child class
3 - function of the parent class by the
object of the child class
2.
Create a class named 'Member'
having the following members:
Data members
1 - Name
2 - Age
3 - Phone number
4 - Address
It also has a function named
'printSalary' which prints the salary of
the members.
Two classes 'Employee' and 'Manager'
inherits the 'Member' class. The
'Employee' and 'Manager' classes
have data members 'specialization'
and 'department' respectively. Now,
assign name, age, phone number,
address and salary to an employee
and a manager by making an object
of both of these classes and print the
same.
3.
Create a class named 'Rectangle' with
two data members 'length' and
'breadth' and two functions to print
the area and perimeter of the
rectangle respectively. Its constructor
having parameters for length and
breadth is used to initialize the length
and breadth of the rectangle. Let
class 'Square' inherit the 'Rectangle'
class with its constructor having a
parameter for its side (suppose s)
calling the constructor of its parent
class. Print the area and perimeter of
a rectangle and a square.
4.
Now repeat the above example to
print the area of 10 squares.
Hint-Use array of objects
5.
Create a class named 'Shape' with a
function to print "This is a shape".
Then create two other classes named
'Rectangle' and 'Circle' inheriting the
Shape class, both having a function to
print "This is rectangular shape" and
"This is circular shape" respectively.
Create a subclass 'Square' of
'Rectangle' having a function to print
"Square is a rectangle". Now call the
function of the 'Shape' and the
'Rectangle' class by the object of the
'Square' class.
BlogsDope App
Get it on Google Play
(https://play.google.com/store/apps/details?
id=com.blogsdope&pcampaignid=MKT-
Other-global-all-co-prtnr-py-
PartBadge-Mar2515-1)
New Questions
(/discussion/i-am-not-getting-the-
below-ques-can-any-one-explai)
(/discussion/we-have-to-calculate-
the-area-of-a-rectangle-a-squ)
Problem -C
(/discussion/problem)
(/discussion/selenium-and-java-
tutorials-plus-exeercises)
Construct a class named 'Shape'
with a function to print "This is a
shape". Then create two other
classes named 'Rectangle' and
'Circle' inheriting th - Cpp
(/discussion/construct-a-class-
named-shape-with-a-function-to-p)
program execution -C
(/discussion/program-execution)
(/discussion/which-platform-will-be-
more-comfortable-for-long-t)
Ask Yours
(/add_question/)
(/discussion/)
(/media/pdf/ASCII.pdf)
(/practice/)
(https://www.facebook.com/codesdope/)
(https://twitter.com/CodesDope)
(https://www.linkedin.com/company/codesdope)
Recent Posts
Shell Sort
Shell Sort
(/blog/article/shell-sort/)
(/blog/submit-article/)
FOLLOW US
(https://www.facebook.com/codesdope) (https://twitter.com/codesdope)
(https://www.pinterest.com/codesdope/)
(https://www.linkedin.com/company/codesdope)
(https://plus.google.com/b/103889423774256807287/103889423774256807287/posts)
CATEGORIES
ABOUT (/about/)
BLOG (/blog/)
COURSES (/)
PRACTICE (/practice/)
DISCUSSION (/discussion/)
CONTACT US (/contact-us/)
TERMS OF USE (/terms-of-use/)
PRIVACY POLICY (/privacy-policy/)
KEEP IN TOUCH
[email protected] (mailto:[email protected])