-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsingInterface.java
More file actions
56 lines (54 loc) · 1.85 KB
/
Copy pathUsingInterface.java
File metadata and controls
56 lines (54 loc) · 1.85 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
interface Electronics
{ void cost(); // Interface consist pure abstract methods , interface by default is abstract and public method.
void battery();
}
abstract class Mobile implements Electronics
{ void simslot()
{ System.out.println( "Every mobile has slimslot");
}}
class Iphone extends Mobile
{ public void cost() // public keyword is mandatory here beacuse cost and battery methods of interface are public.
{System.out.println( "This mobile is 1000");}
public void battery() // Also, methods of the interface must be overridden
{ System.out.println( "This battery is small size");}
}
class Samsung extends Mobile
{ public void cost()
{System.out.println( "This mobile is 9000");}
public void battery()
{ System.out.println( "This battery is big in size");}
}
abstract class Laptop implements Electronics
{ void InbuiltSoftware()
{ System.out.println( "Every laptop has Inbuilt software");
}}
class Dell extends Laptop
{ public void cost() // public keyword is mandatory here beacuse cost and battery methods of interface are public.
{System.out.println( "This laptop is 8000");}
public void battery() // Also, methods of the interface must be overridden
{ System.out.println( "This battery is inside ");}
}
class Mac extends Laptop
{ public void cost()
{System.out.println( "This laptop is 5000");}
public void battery()
{ System.out.println( "This battery has good life time");}
}
class UsingInterface
{ public static void main(String ar[])
{ Mobile x= new Samsung(); // Using upcasting
x.cost();
x.battery();
x.simslot();
x= new Iphone();
x.cost();
x.battery();
x.simslot();
Laptop y= new Dell();
y.cost();
y.battery();
y.InbuiltSoftware();
y= new Mac();
y.cost();
y.battery();
y.InbuiltSoftware();}}