Win a copy of Pragmatic AI this week in the Artificial Intelligence 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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)
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!