-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar_fueldectection.java
More file actions
46 lines (45 loc) · 886 Bytes
/
Copy pathCar_fueldectection.java
File metadata and controls
46 lines (45 loc) · 886 Bytes
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
class Car {
public static void main(String arg[])
{
car1 c1;
ELctric_car e1=new ELctric_car();
petrol_car p1=new petrol_car();
c1=e1;
c1.drive();
e1.charge();
c1=p1;
c1.drive();
p1.fillup();
}
}
interface car1{
public void drive();
}
class ELctric_car implements car1{
int battery=80;
public void drive(){
System.out.println("\nDriving the electric car.");
}
public void charge(){
if(battery==0){
System.out.println("\nPlease charge car!");
}
else{
System.out.println("Car is charge u can use it.");
}
}
}
class petrol_car implements car1{
int petrol=5;
public void drive(){
System.out.println("Driving the petrol car.");
}
public void fillup() {
if(petrol<2){
System.out.println("fill up the petrol ");
}
else{
System.out.println("You can drive the car.");
}
}
}