Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Thread doubt  RSS feed

 
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class XTC {

protected static void main ( String [ ] ka) throws Exception {//1
XTC x = new XTC ( ) ;
x . swim ( ) ;
}

Exception swim ( ) throws Exception{
try
{
throw new ArrayIndexOutOfBoundsException ( ) ;
}
catch (ArrayIndexOutOfBoundsException e ) {
return e ;
}
finally {
System . out . println ( " Highway Star ");
throw new Exception ( ) ;
}
}
}

what will be the output?

also can the main method be declared as protected as in //1
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A main method is like any other method in java , it can be very well declared as protected , you wont get compile time error. But for running the code you need to have main method like public static void main ( String[] a) .

Your code will compile but wont run , if you fix the main method it will print " Highway Star " and exception is thrown.
[ September 22, 2005: Message edited by: Srinivasa Raghavan ]
 
Karu Raj
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey i am not gettting the output.

executed in jdk1.4 >Got output as
---------- Javac ----------
XTC.java:9: 'class' or 'interface' expected
Exception swim ( ) throws Exception
^
1 error
---------------------------------------

Please execute and help meout
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With protected main it compiles (with a warning) but I get this error at runtime

With public main it compiles (again with a warning) and the output is


The warning is

(JDK 1.4.2_01 on Windows)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!