-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractDemo.java
More file actions
44 lines (40 loc) · 827 Bytes
/
Copy pathAbstractDemo.java
File metadata and controls
44 lines (40 loc) · 827 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
package day23;
abstract class Animal{
int lifetime=-1;
abstract void makesound();
void describe() {
System.out.println("this is animal class");
}
}
class Cat extends Animal{
@Override
void makesound() {
System.out.println("meow");
}
}
class Dog extends Animal{
@Override
void makesound() {
System.out.println("lol-lol");
}
}
abstract class Bird extends Animal{
}
class Crows extends Bird{
void makesound() {
System.out.println("ka-ka");
}
}
public class AbstractDemo {
public static void main(String[] args) {
Animal a1=new Cat();
a1.makesound();
a1=new Dog();
a1.makesound();
a1=new Crows();
a1.makesound();
System.out.println(a1 instanceof Animal);
System.out.println(a1 instanceof Dog);
System.out.println(a1 instanceof Bird);
}
}