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{
public static void main(
String argv[]){P2 p2 = new P2();
p2.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 given as 4.
Please let me know in detail why the remaining options are incorrect.
Thank you in advance.
:roll: