์ดํด๋ฆฝ์ค
์ํธ ์ฌํํธ ์์ค override/implement methods
class Shape{
void draw() {
System.out.println("Shape");
}
}
class Line extends Shape{
@Override
void draw() {
System.out.println("Line");
}
}
class Rect extends Shape{
@Override
void draw() {
System.out.println("Rect");
}
}
class Circle extends Shape{
@Override
void draw() {
System.out.println("Circle");
}
}
public class MethodOverEx {
static void paint(Shape s){
s.draw();
}
public static void main(String[] args) {
paint(new Shape());
paint(new Line());
paint(new Rect());
paint(new Circle());
}
}
class Shape{
String name;
void paint() {
draw();
}
void draw() {
System.out.println(name);
}
}
class Circle extends Shape{
String name;
@Override
void draw() {
name = "Circle";
super.name = "Shape";
System.out.println(name);
}
}
public class SuperEx {
public static void main(String[] args) {
Shape s = new Circle(); //์
์บ์คํ
s.paint();
}
}
728x90
๋ฐ์ํ
0