From Wikipedia, the free encyclopedia
class Person {
public void teach(){
System.out.println("Person can teach");
}
}
class Teacher extends Person {
public void teach() {
System.out.println("Teacher can teach in a school");
}
}
public class TestTeacher {
public static void main(String args[]) {
Person person = new Person(); //Person reference and object
Person another_person = new Teacher(); //Person reference, Teacher object
Teacher teacher = new Teacher(); //Teacher reference and obj.
person.teach();//output: Person can teach
// Here you can see Teacher object's method is executed even-
// -though the Person reference was used
another_person.teach();//output: Teacher can teach in a school
teacher.teach();//output: Teacher can teach in a school
}
}
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.