Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to extend or implement classes?
    text
    copied!<p>Picture to show task: <img src="https://i.stack.imgur.com/2s38M.png" alt="enter image description here"></p> <p>First I am sorry, for my bad to for expressing my mind.</p> <p>I have such a task, I don't need that you do it for me.</p> <p><code>Vehicle</code> is parent class for <code>Sedan</code> (Cause Sedan class is String type).</p> <ol> <li>How to extend or implement Vehicle class with universal class?</li> <li>I forgot to ask my teacher, but maybe you will know, what means striped pointer to Owner class, and what is that: <code>has a</code>?</li> </ol> <p>P.S. If you need code that I have written already, I will show you.</p> <p>So this is my parent Vehicle class:</p> <pre><code>public class Vehicle { private int vehicleNumber; protected int fuelTankSize; protected int maxSpeed; protected Owner owner; //1 public Vehicle(int vehicleNumber){ this.vehicleNumber = vehicleNumber; } //2 public Vehicle(int vehicleNumber, int fuelTankSize) { this.vehicleNumber = vehicleNumber; this.fuelTankSize = fuelTankSize; } //3 public Vehicle(int vehicleNumber, int fuelTankSize, int maxSpeed) { this.vehicleNumber = vehicleNumber; this.fuelTankSize = fuelTankSize; this.maxSpeed = maxSpeed; } //4 public Vehicle(int vehicleNumber, int fuelTankSize, int maxSpeed, Owner owner) { this.vehicleNumber = vehicleNumber; this.fuelTankSize = fuelTankSize; this.maxSpeed = maxSpeed; this.owner = owner; } //1 public int getMaxSpeed() { return maxSpeed; } public void setMaxSpeed (int maxSpeed){ this.maxSpeed = maxSpeed; } //2 protected int getFuelTankSize(){ return fuelTankSize; } protected void setFuelTankSize (int fuelTankSize){ this.fuelTankSize = fuelTankSize; } //3 public Owner getOwner(){ return owner; } public void setOwner (Owner owner){ this.owner = owner; } } </code></pre> <p>child Sedan with:</p> <pre><code>public class Sedan extends Vehicle { private String registrationIndex;{ } public Sedan (int vehicleNumber, int fuelTankSize, int maxSpeed, String registrationIndex, Owner owner) { super(vehicleNumber, fuelTankSize, maxSpeed, owner); this.setRegistrationIndex (registrationIndex); } public String getRegistrationIndex (){ return registrationIndex; } public void setRegistrationIndex (String registrationIndex) { this.registrationIndex = registrationIndex; } } </code></pre> <p>second Universal child without an error:</p> <pre><code>public class Universal extends Vehicle { private int trunkSize; public Universal (int vehicleNumber, int fuelTankSize, int maxSpeed, int trunkSize, Owner owner) { super(vehicleNumber, fuelTankSize, maxSpeed, owner); this.setTrunkSize (trunkSize); } public int getTrunkSize() { return trunkSize; } public void setTrunkSize(int trunkSize) { this.trunkSize = trunkSize; } public void printDescription() { super.printDescription(); System.out.println("Universalo bagažinės tūris: " + getTrunkSize() + "l."); } } </code></pre> <p>and some misterious (to me) Owner class:</p> <pre><code>public class Owner { public String firstName; public String lastName; public Owner (String firstName){ this.firstName = firstName; } public Owner (String firstName, String lastName){ this.firstName = firstName; this.lastName = lastName; } } </code></pre> <p>added VechileTest for testing:</p> <pre><code>public class VehicleTest { public static void main(String[] args) { Vehicle vehicleInf = new Vehicle (1, 45, 260); Universal universalInf = new Universal(2, 50, 220, 70); Sedan sedanInf = new Sedan (3, 40, 180, "AVA 123"); vehicleInf.printDescription(); universalInf.printDescription(); sedanInf.printDescription(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload