



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!




Web Design & Development CS-
Web Design & Development CS-
public abstract class Shape{ public abstract void calculateArea(); }
public class Circle extends Shape { private int x, y; private int radius; public Circle() { x = 5; y = 5; radius = 10; }
// 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 A.C. Shape s = null;
//Shape s1 = new Shape(); //cannot instantiate
//abstract class reference can point to concrete subclass s = new Circle();
Web Design & Development CS-
Interfaces
public interface Speaker{ public void speak(); }
public interface Printable{ public void print(); }
Web Design & Development CS-
public class Student implements Printable { private String name; private String address;
public String toString () { return "name:"+name +" address:"+address; }
//providing definition of interface’s print method public void print() { System.out.println("Name:" +name+" address"+address); } }//end of class
public class Politician implements Speaker{ public void speak(){ System.out.println(“Politics Talks”); } }
public class Coach implements Speaker{ public void speak(){ System.out.println(“Sports Talks”); } }