notes5 - Abstract Methods and Classes abstract class...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Abstract Methods and Classes abstract class vaporclass{ abstract vapormethod (String name); } The keyword abstract enables you to provide a method prototype in the class body without its implementation. An abstract class can't be instantiated but it can be subclassed and its abstract methods must be overridden with methods whose implementations are provided. Interface : is a purely abstract class i.e. it contains only abstract methods (no implementations). Thus an interface defines a set of methods a class must implement. Any class that implements each of the methods listed in the interface declares that it implements the interface. A class can implement as many interfaces as it needs to. Interface types act like class types. You can declare vars to be of interface type; declare args of methods to accept interface types; return type of a method can be an interface type. E.g. interface scale { static final int BIG = 0, SMALL = 1; void setscale(int size); } class box implements scale { void setscale(int size) { switch(size) { case BIG: case SMALL: } }
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon