This example shows how a simple java abstract class works
Here “Shape” is the abstract class
abstract class Shape
{
abstract void initial(); // methods only defined…..
abstract void display();
}
class cube extends Shape
{
void initial() // Abstract Methods defined….
{
System.out.println(“Hello !! “);
}
void display()
{
System.out.println(“How are you?”);
}
}
public class Abstract
{
public static void main(String[] args)
{
// Shape S = new Shape(); // error cannot create objects for abstrac classes…..
cube C = new cube();
C.initial();
C.display();
}
}
Here we cannot create “Shape” class object because it is abstract
The output is
Hello !!
How are you?

 

Leave a Reply

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

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.