Sunday, 16 September 2012

Java program codes: Encapsulation Example in java

Encapsulation Example in java

class Check{
    private int amount=0;
    public int getAmount(){
        return amount;
    }
    public void setAmount(int amt){
        amount=amt;
    }
}
public class Mainclass{
    public static void main(String[] args){
        int amt=0;
        Check obj=new Check();
        obj.setAmount(200);
        amt=obj.getAmount();
        System.out.println("Your current amount is :"+amt);
        }
}

output
Your current amount is: 200

No comments:

Post a Comment