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

Dans mock exam 2 ques3

 
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am enclosing the code Dan's mock exam 2 , ques3
The answer given is d .
I want to ask Dan something
class A is declared as public and assuming that both class A and B are in the same file, How would you save the file ? is it A.java or B.java.
If you save it as B.java, then there is a compiler error even before processing of code starts. However, by seeing the code , it seems as though the main method is in the B class.
I guess thats a typo. I am a bit confused

Thanks
Sri
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sri,
There is no chance for confusion in this case. The file name is clearly A.java. It is mentioned. The main() method is in class B.
But the question of main() mehtod comes in to picture only runtime.
So Before running the program using let us say java A (where we can expect runtime error for main not found)we are getting compile time error as we are accessing the private method of class A.
This is really one of the excellent questions as you need to think about a lot of things before answering the question
 
Sridhar Srikanthan
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, thanks Sarma... i dont know how i missed that.
sri
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic