





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















Example of abstract class Shape.java
// providing definition of abstract method public void calculateArea () { double area = 3.14 * (radius * radius); System.out.println(“Area: ” + area); }
}//end of class
public class Test { public static void main (String args[ ]){ //can only create references of abstract class Shape s = null; // Shape s1 = new Shape(); //cannot instantiate abstract class
//can point to the concrete subclass s = new Circle(); s.calculateArea(); } }
Implementing (Using) Interfaces
Example Code
public interface Printable { public void print(); }
public class Student implements Printable{ private String name; private String address;
public String toString () { return "name:"+name +" address:"+address; } // NOT providing implementation of print method }
Defining Interface
Implementing Interface