Just put two files in one directory. Here is an example:
Person.java
public class Person { public String name; public Person(String name) { this.name = name; } public String toString() { return name; } }
Student.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); } }
Starting the Student (since he has the main function) gives us the desired result:
Your name is foo My name is boo surprise!
Chris Bunch May 19 '09 at 2:07 a.m. 2009-05-19 02:07
source share