Wednesday 17 September 2014

Creating Object

Assume I have 2 classes one(Cse412lab2) contains the main method and the other (StackOfmethod) contains different other methods

Creating object of StackOfmethod class

StackOfmethod ob1=new StackOfmethod();

 Overloading Methods


public void method(){
        System.out.println("Nothing to print");
    }
 
    public void method(String name){
        System.out.println("Hello " +name);
     
    }

  Constructor

public StackOfmethod(String name, String Age){
        System.out.println("Hello "+name);
        System.out.println("Your Age " + Age );
             
}

*** class name StackOfmethod

 

Access private variable


    private int x=10;
    private int y=15;
    public void accessPrivateVariable(){
        int res=0;
     
        res =x+y;
        System.out.println(res);
    }

** variable out side any method are called instance variable

No comments:

Post a Comment