Created
November 22, 2015 19:22
-
-
Save GedMullen/1555613e8b147820a486 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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