Hi,
I was going through following question from site
http://www.jchq.net/certkey/0102certkey.htm
Question 9)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();
}
Answer 9)4) P1 compiles cleanly but P2 has an error at compile time
Even though P2 is in the same directory as P1, because P1 was declared with the package statement it is not visible from P2
I have not understood answer. does directory and package both refer same. please advise. thanks in advance
I was going through following question from site
http://www.jchq.net/certkey/0102certkey.htm
Question 9)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();
}
Answer 9)4) P1 compiles cleanly but P2 has an error at compile time
Even though P2 is in the same directory as P1, because P1 was declared with the package statement it is not visible from P2
I have not understood answer. does directory and package both refer same. please advise. thanks in advance