You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Learn/Jb25_ObjExtends.java

29 lines
386 B

public class Jb25_ObjExtends
{
public static void main(String[] args)
{
Student a = new Student();
a.name = "xiaoming";
a.age = 17;
a.study();
}
}
/*
继承的优点:
提高代码复用性
类与类之间产生了关系,给第三个特征多态提供了前提
*/
class Person
{
String name;
int age;
}
class Student extends Person
{
void study()
{
System.out.println(age+"岁的"+name+"正在学习");
}
}