• 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
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Ques from John Hunt's Mock Exam

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey guys
can sum1 tell me how do we choose a proper answer for this question


What is the result of compiling and running this class?

A.The string Test is printed to the standard out.
B.A runtime exception is raised stating that an object has not been created.
C.Nothing is printed to the standard output.
D.An exception is raised stating that the method test cannot be found.
E.An exception is raised stating that the variable this can only be used within an instance.
F.The class fails to compile stating that the variable this is undefined.
Select all correct answers

The correct answer given is F...However even E looks pretty much acceptable because whn I tried to compile and run the program the exact error I got was

non-static variable this cannot be referenced from a static context
this.print();
^
So neither of the answers had the exact match ...so how do we choose the proper answer ??
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exceptions occur during runtime ... So i dont think the usage of the word "exception" in option E makes it a correct choice. Since option F clearly states that it is a compiler error, i would stick with that ...
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Max,

The this reference (ie the reference to the current executing object) is NOT implicitly passed to a static method. Since, a static method is not tied to a specific instance of a class. It results in a compile time eror.
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I agree with Aarti that it will throw a compile time error because of 'this'
being used on a static method.

Kaps
 
reply
    Bookmark Topic Watch Topic
  • New Topic