JDK,JVM,JRE

What is Abstract Class?

Abstract Classes:

  • Abstract class is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).
    When a class is used abstract keyword, then: .
  • It might have abstract method in it.It may not have any abstract method but If we have any abstract method then
    We MUST write abstract before the class.

     

Example

Abstract Classes Example:

public abstract  class Account {


String name;


int id;


long phoneNumber;


 Account( String name,int id,long phoneNumber){


    this.name=name;


    this.id=id;


    this.phoneNumber=phoneNumber;


}


abstract int   calculateFee(); 





public  void savingFee() {


    System.out.println("save 20% dollar");


    System.out.println("always save money");


}


}//class





public class Checking extends Account{


    int balance;


    char gender;


    Checking (String name,int id,long phoneNumber,int balance,char gender){


        super(name,id,phoneNumber);


        this.balance=balance;


        this.gender=gender;


    }


      @Override


      int calculateFee() {


      balance=2005;


      if(balance>200) 


          System.out.println("tax is given");


      else


      System.out.println("tax is not given");


      System.out.println("print the total calculate fee");


      


      return balance; 


      }


    public void print() {


        System.out.println(name);


        System.out.println(id);


        System.out.println(phoneNumber);


        System.out.println(this.balance);


        System.out.println(this.gender);	


    }


public class Saving extends Account{


    int tax;


    Saving (String name,int id,long phoneNumber,int tax){


        super(name,id,phoneNumber);	


}


    @Override


    int calculateFee() {


        return 0;


    }


}





public class Main {





    public static void main(String[] args) {


        Checking Joe;


        Joe=new Checking("Joe",122,24672478,755522,'m');


        System.out.println(Joe.calculateFee());


        Joe.savingFee();


        Joe.print();	


    }


}

 

Visited 1 times, 1 visit(s) today

Comments are closed.

Close