-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQ9_Inheritance2.java
More file actions
80 lines (70 loc) · 1.89 KB
/
Q9_Inheritance2.java
File metadata and controls
80 lines (70 loc) · 1.89 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.util.Scanner;
abstract class Vehicle{
int year_of_manufacture;
Vehicle(){
this.year_of_manufacture = 0;
}
Vehicle(int a){
this.year_of_manufacture = a;
}
abstract int getData();
abstract void putData(int a);
}
class TwoWheeler extends Vehicle{
TwoWheeler(){
super();
}
TwoWheeler(int a){
super(a);
}
int getData(){
return this.year_of_manufacture;
}
void putData(int a){
this.year_of_manufacture = a;
}
}
final class FourWheeler extends Vehicle{
FourWheeler(){
super();
}
FourWheeler(int a){
super(a);
}
int getData(){
return this.year_of_manufacture;
}
void putData(int a){
this.year_of_manufacture =a;
}
}
class MyTwoWheeler extends TwoWheeler{
MyTwoWheeler(){
super();
}
MyTwoWheeler(int a){
super(a);
}
void putData(int a){
super.putData(a);
}
}
class Q9_Inheritance2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
//Object of MyTwoWheeler
MyTwoWheeler mtw = new MyTwoWheeler();
System.out.println("-----------------------------------------");
System.out.print("Enter the year of manufacture of your two wheeler:\t");
int a = sc.nextInt();
mtw.putData(a);
System.out.println("The year of manufacture of my two wheeler is: "+mtw.getData());
System.out.println("-----------------------------------------");
//Object of FourWheeler;
System.out.print("Enter the year of manufacture of the four wheeler:\t");
int b = sc.nextInt();
FourWheeler fw = new FourWheeler(b);
System.out.println("The year of manufacture of the four wheeler is: "+fw.getData());
System.out.println("-----------------------------------------");
}
}