GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 450 of 493    Print  
What happens if public static void main(){} is made protected?

  
Total Answers and Comments: 13 Last Update: May 22, 2008     Asked by: venkat 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: ksatya
 
Nothing happens. The code will run fine. you can have public/private/protected methods. main in one of the method if you make protected. But if you want to execute this as an application then you have to give public static void main.

Thanks,
KSatya

Above answer was rated as good by the following members:
tpran1685, phdsong, muktasharad
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
November 21, 2007 06:15:52   #1  
r.praveenkumar Member Since: October 2007   Contribution: 26    

RE: What happens if public static void main(){} is mad...

it will result in error you will not be able to compile


 
Is this answer useful? Yes | No
November 21, 2007 06:32:56   #2  
ksatya        

RE: What happens if public static void main(){} is mad...
Nothing happens. The code will run fine. you can have public/private/protected methods. main in one of the method if you make protected. But if you want to execute this as an application then you have to give public static void main.

Thanks,
KSatya

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
November 21, 2007 08:00:39   #3  
Sushil Jain        

RE: What happens if public static void main(){} is mad...
You will be able to compile but it will through a run time error saying "main method not public".
 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
November 22, 2007 07:56:30   #4  
satheesh kumar sriramaneni        

RE: What happens if public static void main(){} is mad...
We can able to compile that java file, means we can get the class file.
But we can't get the predicted value.

 
Is this answer useful? Yes | No
November 23, 2007 02:01:17   #5  
Prashant        

RE: What happens if public static void main(){} is mad...
If we made it private then its scope gets changed ie private and hence while runing any java program it will call main method first as becasue its scope is public and hence if it is private then the main would not gets called implicitly we have to call that explicitly
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
November 26, 2007 02:37:47   #6  
sid        

RE: What happens if public static void main(){} is mad...
It gets compiled, but at run time it says that it is not public. Because JVM is not capable to access the static method of main class. Actully JVM is present out side of the class so access modifier is not allowed to do to access the main method.
 
Is this answer useful? Yes | No
December 14, 2007 13:32:07   #7  
prdeep Member Since: December 2007   Contribution: 1    

RE: What happens if public static void main(){} is made protected?

It gets compiled, but at run time it says that it is not public. Because JVM is not capable to access the static method of main class. Actully JVM is present out side of the class so access modifier is not allowed to do to access the main method.


 
Is this answer useful? Yes | No
December 17, 2007 23:05:47   #8  
shaik subhani Member Since: December 2007   Contribution: 11    

RE: What happens if public static void main(){} is made protected?
it will be compiles ,but it displays runtime error by saying main method is not public
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
December 27, 2007 01:14:18   #9  
r.praveenkumar Member Since: October 2007   Contribution: 26    

RE: What happens if public static void main(){} is made protected?

  i am using JCreator java compiler in that i am able to compile and execute the program also if i made main() as protected


 
Is this answer useful? Yes | No
January 03, 2008 01:43:54   #10  
shaik subhani Member Since: December 2007   Contribution: 11    

RE: What happens if public static void main(){} is made protected?
if you declare main method as protected ,it will compile  but it gives runtime error saying as main method is not public.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape