Skip to content

Instantly share code, notes, and snippets.

@GedMullen
Created November 22, 2015 19:22
Show Gist options
  • Save GedMullen/1555613e8b147820a486 to your computer and use it in GitHub Desktop.
Save GedMullen/1555613e8b147820a486 to your computer and use it in GitHub Desktop.
public class Doctor extends CareWorker {
private String manner = " and Informative";
public Doctor(String firstName, String secondName, String speciality){
super(firstName, secondName, speciality);
}
public String getFullName(){
return "Dr " + super.getFullName();
}
public String getFirstAndSecondName(){
return super.getFullName();
}
//Example of overridden method
public String getBedsideManner(){
return super.getBedsideManner() + manner;
}
//Example of overloaded method
public String getBedsideManner(boolean isNightTime){
if(isNightTime){
return getBedsideManner() + " and Quiet";
}else{
return getBedsideManner();
}
}
public static void main(String[] args) {
/*
Doctor doc = new Doctor("Joe", "Blogs", "Brains");
System.out.println(doc.getFullName());
System.out.println(doc.getBedsideManner());
System.out.println(doc.getBedsideManner(true));
*/
//Create Doctor instance with CareWorker reference
CareWorker careWorker = new Doctor("Gary", "Barlow", "Heart");
System.out.println(careWorker.getFullName());
//You need a new reference for each object instance
//CareWorker careWorker2 = new Doctor("Gary", "Barlow", "Heart");
//The getBedsideManner method on the subclass Doctor is executed
System.out.println(careWorker.getBedsideManner());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment