title: Java inheritance - could passing superclass object into a subclass be simplified?
body: <p>We know that</p>
  
  <pre><code>String s = new Object();
  </code></pre>
  
  <p>will result in error:</p>
  
  <pre><code>incompatible types: Object cannot be converted to String
  </code></pre>
  
  <p>Thus, from the following example, we cannot do:</p>
  
  <pre><code>Car car = new Vehicle();
  </code></pre>
  
  <p>But what would be wrong for Java having something like this:</p>
  
  <p>Supperclass:</p>
  
  <pre><code>    public class Vehicle {
          String color;
          int numberOfWheels;
          int maxSpeed;
          // etc.
      }
  </code></pre>
  
  <p>Subclass:</p>
  
  <pre><code>    public class Car extends Vehicle {
  
          String engineType;
          String transmissionType;
          int numberOfDoors;
          // etc.
  
          Car(Vehicle vehicle) {
                              // the theoretical idea of passing
                              // the superclass object within a subclass
              super = vehicle;
          }
      }
  </code></pre>
  
  <p>The 'super = vehicle;' would allow us to pass all values of a previously set superclass (vehicle)
  to new subclasses (car) at one shot.
  And the usage would be:</p>
  
  <pre><code>    public class App {
  
          public static void main(String[] args) {
  
              Vehicle vehicle = new Vehicle();
              vehicle.color = "GREEN";
              vehicle.maxSpeed = 100;
              vehicle.numberOfWheels = 4;
  
              Car car = new Car(vehicle);
  
                                          // this would print: GREEN
              System.out.println("Car color is: " + car.color);
          }
      }
  </code></pre>
  
  <p>Perhaps there already is a simple way of doing it similarly. </p>
  
  <p>"Enlighten those who are still in dark ... "</p>