-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstract.java
39 lines (32 loc) · 1006 Bytes
/
Abstract.java
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
//* Abstract Class Demo (What is the use of the Abstract to use to define the standard)
//* From Abstract we can achieve Security or Abstraction (Hides certain details from the user)
abstract class Parent {
Parent() {
System.out.println("I am an constructor! of the Base Class");
}
public void sayHello() {
System.out.println("Hello, world");
}
abstract public void greet();
}
// ! We cannot implement class without method and inheritance this will give an
// error but you can have an option to create class as a abstract or implement
// the method of the class
abstract class ChildAnother extends Parent {
public void heelo() {
System.out.println("Hello, ChildAnother");
}
}
class Child extends Parent {
@Override
public void greet() {
System.out.println("Hello, Child");
}
}
public class Abstract {
public static void main(String[] args) {
Child c = new Child();
c.greet();
c.sayHello();
}
}