4.26継承のメリットとデメリット
998 ワード
/*
:
。
?
Java :extends
:
class extends {}
:
A:
B:
C: ,
, :
。
: , 。
:
:
*/
//
/*
class Student {
public void eat() {
System.out.println(" ");
}
public void sleep() {
System.out.println(" ");
}
}
class Teacher {
public void eat() {
System.out.println(" ");
}
public void sleep() {
System.out.println(" ");
}
}
*/
//
class Person {
public void eat() {
System.out.println(" ");
}
public void sleep() {
System.out.println(" ");
}
}
class Student extends Person {
}
class Teacher extends Person {
}
class ExtendsDemo {
public static void main(String[] args) {
Student s = new Student();
s.eat();
s.sleep();
System.out.println("-------------");
Teacher t = new Teacher();
t.eat();
t.sleep();
}
}