JAVA 160808 overload overraid
package mypack2;
public class StudentMain {
public static void main(String[] args) {
Student student = new Student("규", 11, "남");
System.out.println(student);
System.out.println(student.toString());
System.out.println("--------------");
StudentTom tom = new StudentTom();
System.out.println(tom.name + " " + tom.grade + " " + tom.gender);
StudentTom tom2 = new StudentTom("톰", 1, "남");
System.out.println();
System.out.println(tom2.name + " " + tom2.grade + " " + tom2.gender);
tom2.study();
System.out.println("--------------");
StudentJames james = new StudentJames();
System.out.println(james.name + " " + james.grade + " " + james.gender);
james.study();
}
}
package mypack2;
//public class Student extends Object {
public class Student {
/*
@Override
public String toString() {
return "자바만세";
}
*/
protected String name;
protected int grade;
protected String gender;
public Student(){
}
public Student(String name, int grade, String gender) {
this.name = name;
this.grade = grade;
this.gender = gender;
}
public void study(){
System.out.println("학생은 공부를 해야한다. 스승을 헐 뜯지 말고...");
}
}
package mypack2;
public class StudentJames extends Student{
@Override
public void study() {
System.out.println("학생은 자바의 객체를 이해해야 한다. 특히 다양성을...");
}
}
package mypack2;
public class StudentTom extends Student{
public StudentTom() {
super(); //생략 가능
}
public StudentTom(String name, int grade, String gender) {
super(name, grade, gender);
}
}
'📁 공부정리 > JAVA' 카테고리의 다른 글
자바 다형성(java polymorphism), 메소드재정의, 다중정의(method overrding, method overloading) (0) | 2016.06.09 |
---|---|
JAVA 160609 추상클래스 (0) | 2016.06.09 |
JAVA 160608 Singleton (0) | 2016.06.08 |
JAVA 160608 자판기 복습 (0) | 2016.06.08 |
JAVA 160608 overload (0) | 2016.06.08 |