Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
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
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter01 : abstract 본문

JAVA/chapter17_abstract_class

chapter01 : abstract

GAWON 2023. 5. 30. 09:13
package org.joonzis.ex;

abstract class Animal{	// 추상 클래스 ( 일반 메소드, 추상 메소드를 모두 가질 수 있다)
	public void eat(String food) {
		System.out.println(food + " 먹는다");
	}
	abstract public void move(); // 추상 메소드
}
class Dog extends Animal{
	@Override
	public void move() {
		System.out.println("강아지 산책한다.");
	}
}
public class Ex01_abstract {
	public static void main(String[] args) {
		
		// 추상 클래스는 new 할 수 없다.(객체 생성 불가)
		//Animal animal = new Animal();
		Animal animal = new Dog();
		animal.eat("사료");
		animal.move();
		
		
		
		
		
		
	}
}

'JAVA > chapter17_abstract_class' 카테고리의 다른 글

chapter02 : abstract  (0) 2023.05.30