3 Replies Latest reply: Dec 26, 2008 1:23 PM by 807589 RSS

    abstract class without abstract method

    807589
      Look at this pice of code. It's ok, but i think that it shouldn't be because in theory in abstract class should be minimum 1 abstract method. So why this code is OK????

      public class Test {
      //Good obstract class without abstract method ????????????
           abstract class Vehicle {
                public int speed() {
                     return 0;
                }
           }


           class Car extends Vehicle {
                public int speed() {
                     return 6;
                }
           }

           public class RaceCar extends Car {
                public int speed() {
                     return 12;
                }
           }

           public static void main(String[] args) {
                RaceCar racer = new Test().new RaceCar();
                Car car = new Test().new RaceCar();
                Vehicle vehicle = new Test().new RaceCar();
                System.out.println(racer.speed() + ", " + car.speed() + ", "
                          + vehicle.speed());
           }

      }