-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMethodOverriding
45 lines (35 loc) · 959 Bytes
/
MethodOverriding
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
public class MethodOverRiding {
public static void main(String[] args) {
Bike bike = new Bike();
bike.getManufactureName("BMW");// get name from own class or child class
bike.getSpeed(500);//get speed from parent class
}
}
class Car {
String manufactureName;
int speed;
void getManufactureName(String manufactureName){
System.out.println("Car's Name Is : "+ manufactureName);
}
void getSpeed(int speed){
System.out.println("Car's Speed is : "+speed);
}
}
class Bike extends Car{
@Override
void getManufactureName(String manufactureName) {
// TODO Auto-generated method stub
// super.getManufactureName(manufactureName);
System.out.println("Bike's Name Is : "+ manufactureName);
}
@Override
void getSpeed(int speed) {
// TODO Auto-generated method stub
super.getSpeed(speed);
// System.out.println("Bike's Speed is : "+speed);
}
}
/*Output of this program
* Bike's Name Is : BMW
Car's Speed is : 500
* */