只需将两个文件放在同一目录中即可。这是一个例子:
人.java
public class Person { public String name; public Person(String name) { this.name = name; } public String toString() { return name; }}
学生.java
public class Student extends Person { public String somethingnew; public Student(String name) { super(name); somethingnew = "surprise!"; } public String toString() { return super.toString() + "t" + somethingnew; } public static void main(String[] args) { Person you = new Person("foo"); Student me = new Student("boo"); System.out.println("Your name is " + you); System.out.println("My name is " + me); }}
运行Student(因为它具有主要功能)会为我们带来所需的结果:
Your name is fooMy name is boo surprise!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)