Tuesday , October 27 2020
Home / Java / JAVA #24 – Abstract Classes in Java

JAVA #24 – Abstract Classes in Java

Abstract Classes

An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.

abstract class GraphicObject {
    int x, y;
    ...
    void moveTo(int newX, int newY) {
        ...
    }
    void draw()
    {
     . . .
    }
    void resize()
    {
     . . .
    }
}
class Circle extends GraphicObject {
    void draw() {
        ...
    }
    void resize() {
        ...
    }
}
class Rectangle extends GraphicObject {
    void draw() {
        ...
    }
    void resize() {
        ...
    }
}
// File name AbstractClasses.java 
 package abstractclasses;
public class AbstractClasses extends Shape{
    
        public void Rectangle()
        {
            System.out.println("This is an Rectangle");
        }
    
    public static void main(String[] args) {               
        AbstractClasses objAbs = new AbstractClasses();
        objAbs.Rectangle();
        objAbs.Triangle();           
    }
    
}
// File name Shape.java and must be store in above package.
package abstractclasses;
public abstract class Shape {
        public void Triangle()
        {
            System.out.println("This is an Triangle of a Shape Class ");
        }
        public void Rectangle()
        {
            System.out.println("This is an Rectangle of a Shape Class ");
        }
}

 

 

About Faheem

An adaptable and responsible Software Engineer, who enjoys working with computers and the opportunity to learn new skills and work with new technologies is particularly attractive to me.

Check Also

JAVA #32 – Java application using SQL server (Part: 01)

  In this part we made the GUI front end of a Application.

Leave a Reply

Your email address will not be published.