• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

regarding main() method

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
i came across the fallowing questions in a mock exam....

question 1)

class XTC {

static void main ( String [ ] args ) { // ---> line 1
int x = true ? 10 : 20 ; // ---> line 2
System . out . println ( x ) ; // ---> line 3
}
}

here i have mark....that it will rise an Exception at runtime saying that there is no main method..

but the Answere is : compiles and prints 10 in the console.

question 02)

class ZZY {

protected static void main ( String [ ] ka ) {
Test t = new Test ( ) ;
t . getInner ( ) . doSomething ( ) ;
}
}

Options :

a . Compiler error - class Test . Inner not accessible from ZZY
b . Compiler error - doSomething is declared abstract in Greater
c . Compiler error - doSomething in Inner can't override doSomething of Greater - the access modifier is not present in Greater
d . Compiles & prints " I'm in inner " to the console on execution

how came the Ans is 'd'? here the main methos is protected....won't it give runti,e exception??

plz give me reply....

thanks in advance

krishna.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trust the javac and java compiler. The answers given are rubbish. Which mock exam did you take?
Paste it and compile it, main must be and only be public. code compiles, but doesn't run.
 
Krishna Bulusu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah.....

these questions r from voodoo....u know in all qusetions they don't declare the main as public..they r giving like

static void main(String args[])....

how come it is possible..??

thanks for ur reply....

krishna.
 
it's a teeny, tiny, wafer thin ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic