Leave a Message To Me

Friday, May 28, 2010

Java Programming : static calling non-static



public class staticClass {
public static int fac(int n){
if (n <= 0)
return 1;
else
return n * fac(n -1);
}
public static void main (String [] args){
System.out.println("Factorial Valu : "+fac(3));
}
}
-----------------------------------------------
public class NonStatic {
public int fac(int n){  
if (n <= 0)
return 1;  
else  
return n * fac(n -1);  
}  
public static void main (String [] args){ 
NonStatic val = new NonStatic (); // create an object to class NonStatic to call the non static method  
System.out.println("Factorial Valu : "+val.fac(3));  
}  
}






0 comments: