// 추상클래스(Abstract class)
abstract class Animal {
// Abstract method (does not have a body)
public abstract void animalSound();
// Regular method
public void sleep() {
System.out.println("Zzz");
}
}
// Subclass (inherit from Animal)
class Pig extends Animal {
public void animalSound() {
// The body of animalSound() is provided here
System.out.println("The pig says: wee wee");
}
}
class MyMainClass {
public static void main(String[] args) {
Pig myPig = new Pig(); // Create a Pig object
myPig.animalSound();
myPig.sleep();
}
}
'PROGRAM > JAVA' 카테고리의 다른 글
Intellij 시작하기 (0) | 2020.11.09 |
---|---|
JDK 1.8.0_271 설치하기 (0) | 2020.10.21 |
Thread TimerEx (0) | 2020.06.20 |
인터페이스 (0) | 2020.06.08 |
Circle Class (0) | 2020.05.05 |