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{
afancymethod();
}
1) Both compile and P2 outputs "What a fancy method" when run
2) Neither will compile
3) Both compile but P2 has an error at run time
4) P1 compiles cleanly but P2 has an error at compile time
SCJP2. Please Indent your code using UBB Code
SCJP2. Please Indent your code using UBB Code
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
SCJP2. Please Indent your code using UBB Code
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
If this were the case don't you think that P2 would have been
able to use P1? Because P2 is in the same directory that P1, it
would have a package name like MyPackage, and it would have acces to P2.
I think that the default package is compound of the java files
without a package sentence. So classes in the default package has
a simple name, with no packages names.
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
What I don't understand is how they changed the earth's orbit to fit the metric calendar. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|