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

How garbage collection is done in java?

551


How to call one constructor from the other constructor ?

606


What is the differences between c++ and java? Explain

588


What are the actions that can occur when a thread enters blocked state?

584


How do you escape sequences in java?

595






Is an array a vector?

558


What is private static class in java?

512


Can a class be declared as static?

680


What are latest features introduced with java 8?

593


What is a void method?

519


What is array initialization in java?

497


What is methods in java?

516


What is a char in java?

539


Is zero a natural number?

568


What does int [] mean in java?

538