Create a class named Shape with a method to print "This is This is shape. Then create two other classes named Rectangle, Circle inheriting the Shape class, both having a method to print "This is rectangular shape and "This is circular shape" respectively. Create a subclass 'Square of Rectangle having a method to print "Square is a rectangle". Now call the method of Shape and "Rectangle class by the object of "Square' class (8 points)
Answers
Answer:
class Shape{
public void Sha(){
System.out.println("This is shape");}
}
class Rectangle extends Shape{
public void Rec(){
System.out.println("This is rectangle shape");}
}
class Circle extends Shape{
public void Cir(){
System.out.println("This is circular shape");}
}
class Square extends Rectangle{
public void Sqa(){
System.out.println("Square is rectangle");}
}
Public class Vamsi{
Public static void main(string[] args){
Square sq=new Square();
sq.Sha();
Sq.Rec();}
}
Explanation:
....
A class named shape with a method to print
" This is a shape ."
Class form {
public void print_shape(){
System.out.println("This is a shape");
}
}
// Rectangle class is a subclass of Shape class
The class Rectangle is Shape{
public void print_rect(){
System.out.println("This is a rectangle");
}
}
// Circle class is a subclass of Shape class
class circle extended shape {
public void print_circle(){
System.out.println("This is a circle");
}
}
// The Square class is a subclass of the Rectangle class
class Square extends Rectangle{
public void print_square(){
System.out.println("A square is a rectangle");
}
}
// main class
class test {
public static void main(String[] args){
square square = new square (); // create an object of class Square
sq.print_shape(); // Square class object that calls the Shape class function
sq.print_rect(); // Square class object that calls the Rectangle class function
}
For more similar reference
https://brainly.in/question/22643977
https://brainly.in/question/38157539
#SPJ3