forked from tugul/CoreJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractClass.java
More file actions
42 lines (33 loc) · 1.19 KB
/
Copy pathAbstractClass.java
File metadata and controls
42 lines (33 loc) · 1.19 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
package classes;
/**
* Abstract class
* - can't be instantiated, only to be subclassed
* - Always public or default when a.m. is not specified. Making it final/private/protected won't compile
* - can have abstract/non-abstract methods with any access modifiers
* - can have non-static or non-final fields, unlike interface
* - can implement interface without required implementation of its methods
* - can be extended by another abstract class without implementation of its abstract methods
*
* Abstract method
* - is declared with keyword abstract
* - doesn't have a body
* - exists only in abstract class
* - can't be private or final
*
*/
interface IFly {
void fly();
}
abstract class Soul implements IFly{
static int age;
String name;
private void sayMyName() { System.out.println("Soul"); }
protected static void setAge(int age) { Soul.age = age; } // this.age -> wrong! 'this' is only for instance reference
protected abstract void setMyName(String name);
}
public class AbstractClass extends Soul {
public void fly(){ System.out.println(); }
protected void setMyName(String name) { this.name = name; }
public static void main(String[] args) {
}
}