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

Marcus Green "package question"

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You have these files in the same directory. What will happen when you attempt to compile and run Class1.java if you have not already compiled Base.java





1) Compile Error: Methods in Base not found
2) Compile Error: Unable to access protected method in base class
3) Compilation followed by the output "amethod"
4)Compile error: Superclass Class1.Base of class Class1.Class1 not found



The answer is (4)
Can anybody tell the reason!



Regards,
cmbhatt
[ April 17, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you correctly paste the code?
The question states that both classes are in the same directory, so it makes no sense that they are in different packages.
If you remove the package declarations from the code then you'll see that answer 4 is indeed correct.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup Custer, I have correctly pasted the code, the answer to this question says
"This question tried to make you fool against the automake feature of the javac if classfile(that your class is referencing to) doesn't exist it will automatically create that too".

But this is not the issue!


Did you get the question? Please tell me the correct answer!


Regards,
cmbhatt
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure if the import statement fixes the glitch.

Base (Class) itself has default access. So the class is not visible outside the package.

Let the two files be in the same directory or different directory, when you try to compile Class1
a) It should be under a directory Class1. (Class1/Class1.java)
b) Since there was no import statement for Base, the compiler assumes that Base is in the same directory, so searches for Class1.Base and doesn't find it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic