File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cant think of one:-)

 
Suresh Chidambaram
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont remember from where - most prolly marcus green exam 2:
//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
Answer to Question 9: 4.
"The package statement in P1.java is the equivalent of placing the file in a different directory to the file P2.java and thus when the compiler tries to compile P2 an error occurs indicating that superclass P1 cannot be found."
No problem with the answer but the explanation beats me. Firstly, the whole question is ambigous. One must assume the directory being talked about is one named MyPackage and whose parent directory is in the classpath. Otherwise, ofcourse, P1 wouldnt compile.
"The package statement in P1.java is the equivalent of placing the file in a different directory to the file P2.java"
Does this mean that one doesnt actually need to place P1.java in a directory called X/MyPackage where X is a directory in the classpath?Merely putting a package statement would simulate the effect??
No problem with the final answer, though!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic