-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractionn.java
More file actions
42 lines (40 loc) · 1.06 KB
/
Copy pathAbstractionn.java
File metadata and controls
42 lines (40 loc) · 1.06 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
/*abstract means just some concept..no need to be implemented.
Abstraction can be achieved in two ways:1)usng abstract class kywd 2)using interface(pure abstraction).
an abtract classs created using abstract keyword
it can have abstract and non abstact methods
it cannot be instantiated.
can have constuctor and static method also.
*/
abstract class Animal{ //cant create object coz animal is only concept..only blueprint..cant actually created
abstract void walk(); // cant create body
public void eats() //non abtrct method
{
System.out.println("they eats");
}
}
class Horse extends Animal{
public void walk()
{
System.out.println("walk on four legS");
}
}
class chicken extends Animal{
public void walk()
{
System.out.println("walk on two legS");
}
}
public class Abstractionn{
public static void main(String []args)
{
Horse h1= new Horse();
h1.walk();
h1.eats();
//Animal a1=new Animal(); Animal is abstract; cannot be instantiated
//a1.walk();
}
}
/*output
walk on four legS
they eats
*/