- package com.dongchao;
- class Person
- {
- String name;
- int age;
- }
- class Student extends Person
- {
- void study()
- {
- System.out.println("...study...");
- }
- }
- class Worker extends Person
- {
- void work()
- {
- System.out.println("...work...");
- }
- }
- class ExtendsDemo {
- public static void main(String[] args)
- {
- Student stu = new Student();
- stu.name = "xiaoming";
- System.out.println(stu.name);
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/2012201615205.html
来源: http://www.codesnippet.cn/detail/2012201615205.html