• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Package

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could somebody explain me the exact reason for this Question..

What happens when you attempt to compile and run these two files in the
same directory?
//File P1.java
package MyPackage;
class P1{
void afancymethod(){
System.out.println("What a fancy method");
}
}
//File P2.java
public class P2 extends P1{
void afancymethod()
{
}
}
a. Both compile and P2 outputs "What a fancy method" when run
b. Neither will compile
c. Both compile but P2 has an error at run time
d. P1 compiles cleanly but P2 has an error at compile time
Plz explain me in detail as i am very weak in Packages as i havent done anything practically
Thanx
Kaushik
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer is D.
You can compile them by yourself.If you want to compile and run them successfully.You must do like this.
1,You must declare class P1 as public class;

2,Compile P1.java with the command line list below:

3,You must import class MyPackage.P1 before you define class P2;

or declare class P2 like this:

4,You must define a method named main in file P2.java if you want to run it.

5,You must make sure the current directory "." in your system's CLASSPATH variable.
------------------
Java lover from hell!
[This message has been edited by Metal Zhang (edited August 17, 2001).]
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic