Last active
May 14, 2020 06:55
-
-
Save Devcodpanda/05301845053f4ffaa4620fbc79273abe to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Boat extends Vehicle { | |
public Boat(String brand){ | |
super(brand); | |
} | |
public String doStuff() { | |
return ("Je suis " + getBrand() + " et je fais glou glou!"); | |
} | |
} |
This file contains hidden or 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 Car extends Vehicle { | |
public Car(String brand){ | |
super(brand); | |
} | |
public String doStuff() { | |
return ("Je suis " + getBrand() + " et je fais vroum vroum!"); | |
} | |
} |
This file contains hidden or 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
class Hangar { | |
Hangar() { | |
} | |
public static void main(String[] var0) { | |
Car var1 = new Car("307"); | |
Boat var2 = new Boat("Betty"); | |
System.out.println(var1.doStuff()); | |
System.out.println(var2.doStuff()); | |
} | |
} |
This file contains hidden or 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 abstract class Vehicle { | |
// attributes | |
private String brand; | |
private int kilometers; | |
// constructors | |
public Vehicle(String brand) { | |
this.brand = brand; | |
this.kilometers = 0; | |
} | |
// method | |
public abstract String doStuff(); | |
// getters and setters | |
public String getBrand() { | |
return this.brand; | |
} | |
public void setBrand(String brand) { | |
this.brand = brand; | |
} | |
public int getKilometers() { | |
return this.kilometers; | |
} | |
public void setKilometers(int kilometers) { | |
this.kilometers = kilometers; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment