What happens when a main method is declared as private?

Answer Posted / kundan

when u will declare main method is private
it will successfully compile and Run
and result will publish,

class A
{
int x=7;
void show(){
System.out.println(x);
}
}
class Test
{
private static void main(String args[])
{
A a = new A();
a.show();
}
}

out put:-
Main method not public

Is This Answer Correct ?    7 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Where import statement is used in a java program?

587


What is the public field modifier?

520


What is variable declaration and definition?

518


What is the same as procedures?

518


What is difference between equal and == in java?

496






Why main method is static in java?

572


Which package is used for pattern matching with regular expressions?

611


Is a string literal?

502


What do you understand by classes in java?

527


What is the default size of set in java?

479


How to sort an array in java without using sort method?

504


Why do we use threads in java?

544


What is the difference between exception and error in java?

473


What is flush () in java?

535


How can you make sure that your singleton class will always return single instance in multi-threaded environment?

539