Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
java
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; public class Vehicle{ protected double engine; protected String color; public Vehicle(){} public Vehicle(String color){ this.setColor(color); } public Vehicle(double engine){ this.setEngine(engine); } public Vehicle(String color, double engine){ this.setColor(color); this.setEngine(engine); } public String getColor(){ return this.color; } public void setColor(String color){ this.color = color; } public double getEngine(){ return this.engine; } public void setEngine(double engine){ this.engine = engine; } public void printDescription(){ System.out.println("paint in " + getColor() + "; engine " + getEngine() + " liter"); } } public class Truck extends Vehicle { protected int wheels = 4; protected int capCapacity = 4; public Truck(){} public Truck (String color, double engine, int wheels){ super(color, engine); this.setWheels(wheels); } public Truck (String color, double engine, int wheels, int capCapacity){ super(color, engine); this.setCapCapacity(capCapacity); this.setWheels(wheels); } public int getCapCapacity(){ return this.capCapacity; } public void setCapCapacity(int cabCapacity){ this.capCapacity = cabCapacity; } public int getWheels(){ return this.wheels; } public void setWheels(int wheels){ this.wheels = wheels; } public void printDescription(){ super.printDescription(); System.out.println("wheels " + this.getWheels() + "; cab capacity " + this.getCapCapacity()); } } public class Car extends Vehicle { protected String type; public Car(){} public Car(String color, double engine, String type){ super(color, engine); this.setType(type); } public void setType(String type){ this.type = type; } public String getType(){ return this.type; } public void printDescription(){ super.printDescription(); System.out.println("car is a " + this.getType()); } } public class Unit6Assign { /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println("Creating a new car "); Car bmw = new Car("white", 4.5, "Coupe"); bmw.printDescription(); System.out.println(); System.out.println(); System.out.println("Creating a new truck "); Truck ford = new Truck("Red", 7.5, 18, 7); ford.printDescription(); } }
run
|
edit
|
history
|
help
0
currency.java
Problem_OnOff
Construct Tree from Ancestor Matrix
Series_4_8
move zeros to end of array
reserve array value
LRU cache - Using doubly linked list (Fast!)
jb6.13 varargs
Brackets balancing
Central Inteligence Agency