Assignment 4
Assignment 4
: 22BCE7765
Assignment-4 DATE-10/04/2023
1. Create a class 'Degree' having a method 'getDegree' that prints "I got a
degree". It has two subclasses namely 'Undergraduate' and 'Postgraduate'
each having a method with the same name that prints "I am an
Undergraduate" and "I am a Postgraduate" respectively. Call the method
by creating an object of each class and print the student details (name,
regno, degree, years) by creating a method “display” in class Degree.
Code:
class Degree
String name;
String regno;
String degree;
int years;
this.name = name;
this.regno = regno;
this.degree = degree;
this.years = years;
{
System.out.println("I got a degree");
System.out.println("I am an Undergraduate");
}
class Postgraduate extends Degree
System.out.println("I am an Postgraduate");
class Q1
obj1.getDegree();
obj1.display();
obj2.getDegree();
obj2.display();
}
Output:
Code:
class Shapes
private double r;
private double a;
private double w;
private double h;
private double b;
this.r = r;
this.a = a;
this.w = w;
this.h = h;
this.b = b;
}
r = newr;
return r;
a = newa;
return a;
w = neww;
{
return w;
h = newh;
return h;
b = newb;
return b;
System.out.println("Area is 0");
}
class circle extends Shapes
super(r,a,w,h,b);
super(r,a,w,h,b);
}
}
super(r,a,w,h,b);
super(r,a,w,h,b);
class Q2
obj1.calculatearea();
obj2.calculatearea();
obj3.calculatearea();
obj4.calculatearea();
Output:
Code:
package example;
obj.show();
package Questions;
import example.code1;
obj.show();
}
Output: