Last active
December 17, 2015 20:29
-
-
Save jpotts18/5667670 to your computer and use it in GitHub Desktop.
Inheritance, abstract, interface
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 Bathroom extends Room implements Flushable{ | |
// inherited attr | |
// length | |
// width | |
public double bathtub = 0.5; | |
public boolean hasShower; | |
@Override | |
public int getArea(){ | |
// can be overridden? | |
} | |
// inherited from Flushable | |
public void flush(){ | |
} | |
public void plunge(){ | |
} | |
public void callOutForToiletPaper(){ | |
} | |
} |
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 Building{ | |
// class variables | |
Door mFrontDoor | |
Door mLastDoor | |
String mAddress | |
// overloaded constructors | |
public Building(){ | |
} | |
public Building(String address){ | |
mAddress = address; | |
} | |
// accessors | |
public getAddress(){ | |
return mAddress; | |
} | |
public setAddress(String address){ | |
mAddress = address; | |
} | |
} |
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 interface Flushable{ | |
public void flush(){} | |
public void plunge(){} | |
public void callOutForToiletPaper(){} | |
} |
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 House extends Building{ | |
// constants | |
Room mLivingRoom | |
List<Bathoom> mBathrooms = ArrayList<Bathroom>(); | |
// constructor | |
public House(){} | |
public List<Bathroom> getBathrooms(){ | |
return mBathrooms; | |
} | |
} |
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
abstract public class Room{ | |
int mLength | |
int mWidth | |
Room(){} | |
Room(int length, int width){ | |
mLength = length; | |
mWidth = width; | |
} | |
public int getArea(){ | |
return mLength * mWidth | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment