Smart Phone Example using Abstract Class in Java


An abstract class is a class marked with the abstract keyword. It, contrary to non-abstract class, may contain abstract - implementation-less - methods. It is, however, valid to create an abstract class without abstract methods. An abstract class cannot be instantiated. It can be sub-classed (extended) as long as the sub-class is either also abstract, or implements all methods marked as abstract by super classes.

Source Code

//Example for Abstract Class in Java Programming
abstract class Mobile {
    void VoiceCall() {
        System.out.println("You can Make Voice Call");
    }
    abstract void camera();
    abstract void touchDisplay();
 
}
class samsung extends Mobile
{
 
    @Override
    void camera() {
        System.out.println("16 Mega Pixel Camera");
    }
 
    @Override
    void touchDisplay() {
        System.out.println("5.5 inch Display");
    }
}
 
class Nokia extends  Mobile
{
 
    @Override
    void camera() {
        System.out.println("8 Mega Pixel Camera");
    }
 
    @Override
    void touchDisplay() {
        System.out.println("5 inch Display");
    }
 
    void fingerPrint() {
        System.out.println("Fast Finger Sensor..");
    }
}
public class abstractDemo2 {
    public static void main(String args[]) {
 
        samsung M32 =new samsung();
        M32.VoiceCall();
        M32.touchDisplay();
        M32.camera();
        System.out.println("-------------------------");
        Nokia N1= new Nokia();
        N1.VoiceCall();
        N1.camera();
        N1.touchDisplay();
        N1.fingerPrint();
 
    }
}
 

Output

You can Make Voice Call
5.5 inch Display
16 Mega Pixel Camera
-------------------------
You can Make Voice Call
8 Mega Pixel Camera
5 inch Display
Fast Finger Sensor..
To download raw file Click Here

Basic Programs