Doubt in the Module3 Exercise Programs | Selenium Forum
M
Posted on 06/12/2015
Program:
public class Test {
int age;
String name;

Test(){
non_static_meth();
static_meth();
}
public static void main(String[] args) {

Test t1 = new Test();


}

public void non_static_meth(){
System.out.print("NM ");
}

public static void static_meth(){
System.out.println("SM");

}

}


My Expectation of output is to print Nothing

Because when the program is executed it will go to main function and as there are no printable statements in main function it prints nothing this is as per my understanding, please correct me if i am wrong

But it is printing NM and SM

M
Replied on 06/12/2015

Hi
it is not necessary that the main function needs to have print statements.
Here the main function will give a call for the function that are included in it and that function will print the statements , which is happening in this case

Thanks,
Sarabjit