public class Person
{
String name;
public int age;
protected int height;
private int weight;
public int getHeight()
{
return height;
}
public void setWeight(int weight)
{
this.weight = weight;
}
public int getWeight()
{
return weight;
}
}
Student.java
public class Student extends Person
{
void set(String name, int age, int height, int weight)
{
super.name = name;
super.age = age;
super.height = height;
setWeight(weight);
}
static void print(Student s)
{
System.out.println(s.name+", "+s.age);
System.out.println(s.getHeight()+"cm, "+s.getWeight()+"kg");
}
public static void main(String[] args)
{
Student s = new Student();
s.set("Jiniusman", 25, 175, 62);
print(s);
}
}
result)
댓글 없음:
댓글 쓰기