*****************************
Speedboat.java Illustrates inheritance from Ship class. See SpeedboatTest.java for a test.
*****************************
/** A fast Ship. Red and going 20 knots by default.
*
***********************
public class Speedboat extends Ship {
private String color = "red";
/** Builds a red Speedboat going N at 20 knots. */
public Speedboat(String name) {
super(name);
setSpeed(20);
}
/** Builds a speedboat with specified parameters. */
public Speedboat(double x, double y, double speed,
double direction, String name,
String color) {
super(x, y, speed, direction, name);
setColor(color);
}
/** Report location. Override version from Ship. */
public void printLocation() {
System.out.print(getColor().toUpperCase() + " ");
super.printLocation();
}
/** Gets the Speedboat's color. */
public String getColor() {
return(color);
}
/** Sets the Speedboat's color. */
public void setColor(String colorName) {
color = colorName;
}
}
**********************
SpeedboatTest.java
**********************
/** Try a couple of Speedboats and a regular Ship.
*
*****************************
public class SpeedboatTest {
public static void main(String[] args) {
Speedboat s1 = new Speedboat("Speedboat1");
Speedboat s2 = new Speedboat(0.0, 0.0, 2.0, 135.0,
"Speedboat2", "blue");
Ship s3 = new Ship(0.0, 0.0, 2.0, 135.0, "Ship1");
s1.move();
s2.move();
s3.move();
s1.printLocation();
s2.printLocation();
s3.printLocation();
}
}
*****************************
Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10392
Categories:Programming Code Examples, Java/J2EE/J2ME, Object Oriented Programming
Tags:Java/J2EE/J2MEObject Oriented Programming
Post Data:2017-01-02 16:04:39
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada
