Some important points of Abstract class-
- We can't create the object of abstract class but abstract class have constructor.
- Abstract class constructor is called via super() call from child class constructor.
- Abstract class does not allow abstract method static. if you does it's abstract method static then compiler gives you compilation error message -
illegal combination of modifiers: 'abstract' and 'static' .
- We can apply static with non-abstract method inside Abstract class.
public class AbstarctionDemo extends  MarketChoice{
 public AbstarctionDemo(String[] productName) {
  super(productName);
  // TODO Auto-generated constructor stub
 }
 public static void main(String[] args) {
  // TODO Auto-generated method stub
        String[] productName= {"mouse","keyboard","desktop","cpu","speaker"};
 MarketChoice marketChoice= new AbstarctionDemo(productName);
 marketChoice.getDetails();
 }
 @Override
 public void getMarketDetails() {
  // TODO Auto-generated method stub
  //marketChoice
 }
}
abstract class MarketChoice {
 protected String[] pName;
 //Abstract class constructor  
 public MarketChoice(String[] name){
  pName=name;
 }
 public abstract void getMarketDetails();
 void getDetails(){
  for (String string: pName) {
   System.out.println(string);
  } 
 }
}
 
Nice .
ReplyDelete