Abstract Class Example in Java Program

By | December 17, 2010
Abstract Class Example in Java Program. You can find Abstract Class, Abstract method, Abstract Concept program (code snippets) in this page.

Abstract Class Example in Java Program. You can find Abstract Class, Abstract method, Abstract Concept program (code snippets) in this page.

abstract class Shape{

abstract void draw();

}

class Rectangle extends Shape{

void draw(){

System.out.println(“Drawing Rectangle”);

}

}

class Traingle extends Shape{

void draw(){

System.out.println(“Drawing Traingle”);

}

}

class AbstractDemo{

public static void main(String args[]){

Shape s1=new Rectangle();

s1.draw();

s1=new Traingle();

s1.draw();

}

}

Result:

Drawing Rectangle

Drawing Traingle

4 thoughts on “Abstract Class Example in Java Program

  1. venkatesh

    i want to know explanation about what is abstract class and method

    Reply
  2. selvi

    you will want to create a super class that only defines a generalized form that will be shared by all of its sub classes, leaving it to each subclass to fill in the details. Such a class determines the nature of the methods that the sub classes must implement. One way this situation can occur is when a super class is unable to create a meaningful implementation for a method.

    Reply
  3. rajtravelsss

    I want to more information about abstract method or class.

    Reply
  4. Vivek Ghavle

    But same thing can achieve without Abstract class so why to use it

    class Rectangle {

    void draw(){

    System.out.println(“Drawing Rectangle”);

    }

    }

    class Traingle {

    void draw(){

    System.out.println(“Drawing Traingle”);

    }

    }

    class AbstractDemo{

    public static void main(String args[]){

    Rectangle s1=new Rectangle();

    s1.draw();

    Traingle s2=new Traingle();

    s2.draw();

    }

    }

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *