上个Demo和图欣赏一下:
class Person
{
String name;
int age;
}
class Student extends/*继承*/ Person
{
void study()
{
System.out.println(name+"..Student Study.."+age);
}
}
class Worker extends/*继承*/ Person
{
void work()
{
System.out.println(name+"..Worker Work.."+age);
}
}
public class ExtendsDemo
{
public static void main(String[] args)
{
Student s = new Student();
s.name = "xiaoming";
s.age = 20;
s.study();
Worker w = new Worker();
w.name = "aaaa";
w.age = 31;
w.work();
}
}