-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path18_Practice question on Inheritance
50 lines (41 loc) · 1.1 KB
/
18_Practice question on Inheritance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.company;
class Circle{
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}
public int radius;
Circle(int r){
System.out.println("I am a circle parameterized constructor");
this.radius=r;
}
public double area(){
return Math.PI*this.radius*this.radius;
}
}
class Cylinder extends Circle{
public int height;
Cylinder(int r, int h){
super(r); // When we use super keyword so we basically call the constructor which passes an integer value in it
System.out.println("I am a cylinder parameterized constructor");
this.height=h;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public double volume(){
return Math.PI*this.radius*this.radius*this.height;
}
}
public class practiceset5 {
public static void main(String[] args) {
// Problem 1
//Circle objC = new Circle(8);
Cylinder obj = new Cylinder(8,4);
}
}