0% found this document useful (0 votes)
965 views

Practice Questions of CPP - Subclass

Uploaded by

Shubham Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
965 views

Practice Questions of CPP - Subclass

Uploaded by

Shubham Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

(/)

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.

Download Our App.

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

i am not getting the below ques


can any one explain this with
code - Java

(/discussion/i-am-not-getting-the-
below-ques-can-any-one-explai)

We have to calculate the area of


a rectangle, a square and a circle.
Create an abstract class 'Shape'
with three abstract methods
namely 'RectangleAre - Java

(/discussion/we-have-to-calculate-
the-area-of-a-rectangle-a-squ)

Problem -C

(/discussion/problem)

Selenium and Java tutorials plus


exercises. - Java

(/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)

Which Platform will be more


comfortable for long term goals
in python ??..is it MAC,windows
or Linux/ubuntu?? - Python

(/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/)

HTML V/S XML


(/blog/article/html-vs-xml/)

Expression Parsing: Part 2


(/blog/article/expression-
parsing-part-2/)
JavaScript: AJAX
(/blog/article/javascript-ajax/)
Post Yours

(/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])

© 2016-19 | www. codesdope.com (/) | All rights reserved.

You might also like