fixed by Calling private String name
as private Static String name;
Now on putting the instance variable
as static we will get the Correct Result
package pack2;
import java.lang.*;
import java.util.*;
public class
What_static_void_main {
/*
Note that Only on Declaring the instance variable as static the
program gets compiled and runs, otherwise even if we declare the variable
as public the program will not get
compiled
*/
private static String name="";
public void
setOrderlyName(String name){
this.name = name;
}
public String
getOrderlyName(){
return name;
}
public static void main(String[]
args) {
What_static_void_main
ws = new What_static_void_main();
ws.setOrderlyName("Balaji");
System.out.println(name);
}
}
No comments:
Post a Comment