Abstract class example

Abstract class example
 package com.ram;

abstract class Mobile{
 String name;
 String os;
 String model;
 
 public abstract void display();
}

class Samsung extends Mobile{

 @Override
 public void display() {
  name = "Samsung";
  os = "Android";
  model = "Galaxy SIII";
  System.out.println(name+" "+model+" uses "+os+" operating system");
 }
}

public class AbstractClassExample {
 public static void main(String[] args) {
  Mobile obj = new Samsung();
  obj.display();
 }
}

 
Execute AbstractClassExample class and you get the below output:
Samsung Galaxy SIII uses Android operating system

No comments:

Post a Comment