What happens when a main method is declared as private?
Answers were Sorted based on User's Feedback
Answer / harsha
When a method is declared as private, the program compiles
properly but it will give runtime error ?Main method not
public"
| Is This Answer Correct ? | 111 Yes | 8 No |
Answer / yogesh gandhi
Wrong Vani.
The output of the program is
C:\>javac abc.java
C:\>java abc
Main method not public.
| Is This Answer Correct ? | 72 Yes | 5 No |
Answer / amit kumar chaubey
If the main function is made private...it will compile
Sucessfully...and at the time of execution...it will
execute successfully...but desired result will not be
obtained. After execution..folowin message will be printed:
Main method not public.
| Is This Answer Correct ? | 25 Yes | 3 No |
Answer / srinivasa
JVM is also a program. If main() is declared as privateit
is not available outside of that class . So JVM through the
exception.
| Is This Answer Correct ? | 15 Yes | 5 No |
Answer / 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 |
Answer / r.jainrocks@gmail.com
Byte that have main() implementation can become starting
point of program .
if a program have no main()
i.e.
public static void main(String[] args)
properly it can't become starting point in application
it can be use through other program which capable to become
starting point.
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / subha narayan mohapatra
it will generate an error message because main() method is
the start or execution point in our java program.
| Is This Answer Correct ? | 4 Yes | 2 No |
Answer / sagar chavan
If the main function is made private,
we can do it but the starting point of project should be changed. By default it is main.
| Is This Answer Correct ? | 3 Yes | 1 No |
What are the main concepts of oops in java?
What is a generic data type?
How is java created?
what are the diffrences between interface and abstract class?
Difference between Web-based applications,Client- Server applications and Distributed applications?
what is Inheritense
84. try { 85. ResourceConnection con = resourceFactory.getConnection(); 86. Results r = con.query(”GET INFO FROM CUSTOMER”); 87. info = r.getData(); 88. con.close(); 89. } catch (ResourceException re) { 90. errorLog.write(re.getMessage()); 91. } 92. return info; Which is true if a ResourceException is thrown on line 86? 1 Line 92 will not execute. 2 The connection will not be retrieved in line 85. 3 The resource connection will not be closed on line 88. 4 The enclosing method will throw an exception to its caller.
why java does not contain pointers?
what is the difference between future and callable interface in java?
Difference between start() and run() method of thread class?
If we allocate the memory using 'new' & de-allocated using 'free' then what will happen?
What is a java lambda expression?