Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
java
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//'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(); } }
[
+
]
Show input
Compilation time: 0.73 sec, absolute service time: 0,85 sec
fork mode
|
history
|
discussion