Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Dms - 6569a3dc02dbcjava Assignment5

1. Create parent and child classes with methods to call methods from each class using objects. 2. Create Point2D class with private/public members and subclasses Point3D to test methods. 3. Create Circle class inheriting from Point2D with data/methods and subclass Cylinder to test Circle and Cylinder methods.

Uploaded by

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

Dms - 6569a3dc02dbcjava Assignment5

1. Create parent and child classes with methods to call methods from each class using objects. 2. Create Point2D class with private/public members and subclasses Point3D to test methods. 3. Create Circle class inheriting from Point2D with data/methods and subclass Cylinder to test Circle and Cylinder methods.

Uploaded by

antaraprasad2017
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT NO- 5

TOPIC: Inheritance in Java

1. Create a class with a method that prints "This is parent class" and its subclass with another
method that prints "This is child class". Now, create an object for each of the class and call
1 - method of parent class by object of parent class
2 - method of child class by object of child class
3 - method of parent class by object of child class

2. Create a class Point2D with the data member and methods shown in the class diagram. Note
that the items with a minus sign (-) indicate private members and items with a plus sign (+)
indicate public members. Create a subclass called Point3D which is derived from the
superclass Point2D.Test the methods of both the classes by creating objects in the main
method of another class.

3. Create a derived class Circle inherited from the class Point2D (created in the previous
question) with the data member and methods shown in the following class diagram. Create a
subclass called Cylinder which is derived from the superclass Circle. Test the methods of
Circle and Cylinder classes by creating objects in the main method of another class
4. Create a class named 'Member' having the following members:
Data members
1 - Name
2 - Age
3 - Phone number
4 - Address
5 - Salary
It also has a method 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.

5. Write a superclass called Shape (as shown in the class diagram), which contains:
a. Two instance variables color (String) and filled (boolean).
b. Two constructors: a no-argument constructor that initializes the color to "green" and
filled to true, and a constructor that initializes the color and filled to the given values.
c. Getter and setter for all the instance variables. By convention, the getter for a
boolean variable xxx is called isXXX() (instead of getXxx() for all the other types).
d. A toString() method that returns "A Shape with color of xxx and filled/Not filled". Write
a test program to test all the methods defined in Shape.
Write two subclasses of Shape called Circle and Rectangle, as shown in the class diagram.
The Circle class contains:

 An instance variable radius (double).


 Three constructors as shown. The no-arg constructor initializes the radius to
1.0.
 Getter and setter for the instance variable radius.
 Methods getArea() and getPerimeter().
 Override the toString() method inherited, to return "A Circle with radius=xxx,
which is a subclass of yyy", where yyy is the output of the toString() method
from the superclass.

The Rectangle class contains:

 Two instance variables width (double) and length (double).


 Three constructors as shown. The no-arg constructor initializes the width and length
to 1.0.
 Getter and setter for all the instance variables.
 Methods getArea() and getPerimeter().
 Override the toString() method inherited, to return "A Rectangle with width=xxx and
length=zzz, which is a subclass of yyy", where yyy is the output of the toString()
method from the superclass.

Write a class called Square, as a subclass of Rectangle. Square has no instance


variable, but inherits the instance variables width and length from its superclass
Rectangle.

 Provide the appropriate constructors (as shown in the class diagram).


Hint: public Square(double side) {
super(side, side); // Call superclass Rectangle(double, double)
}
 Override the toString() method to return "A Square with side=xxx, which is a
subclass of yyy", where yyy is the output of the toString() method from the
superclass.
 Override the setLength() and setWidth() to change both the width and length, so
as to maintain the square geometry

You might also like