ways to create an object in Java Example 1

Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)

1309

Program:

 // Save it as File name : Factorial.java
//ways to create an object in Java

class Factorial{
 void fact(int  n){
  int fact=1;
  for(int i=1;i<=n;i++){
   fact=fact*i;
  }
 System.out.println("factorial is := "+fact);
}

public static void main(String args[]){
	
 new Factorial().fact(4);//calling method with anonymous object
 
 }
}

Output:

factorial is := 24
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.