//Chapter 9 inheritance stuff crammed into here // abstract superclass public class Inheritance6 { public static void main( String[] args ) { //X x1 = new X(); //syntax error. can not instantiate abstract class X x1; //can have a abstract class reference variable Y y1 = new Y(); W w1 = new W(); y1.m1(); w1.m1(); y1.m2(); w1.m2(); } } //abstract class has abstract method(s) //abstract class can not be instantiated. //can provide some inherited methods and fields. //use for a class type that is too "abstract" to have actual objects, //provide some common code for subclasses and require them to implement //certain functionality (the abstract methods) abstract class X { int i=3; void m1() { System.out.println( "hello from X m1()" ); } //abstract method has no body abstract void m2(); } //class that derives from an abstract class MUST implement the abstract methods //or else be abstract itself class Y extends X { void m2() { System.out.println( "hello from Y m2()" ); } } class W extends X { void m2() { System.out.println( "hello from W m2()" ); } }