on 09-21-2006 7:53 AM
hello i m a beginner in java trying 4 a job. Kindly help me in solving these question.
wat 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();
}
}
Options---
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 as error at compile time
Hi Payal,
Just check the file if it has closing braces. if the first file is
package MyPackage;
class P1{
void afancymethod(){
System.out.println("What a fancy method");
}
<b>}</b>
Then option 4 is correct ie. P1 compiles cleanly but P2 as error at compile time
But if there is no closing braces for the class P1 then option 2 is correct ie neither will get complied.
If you find my answers helpful, award points.
Regards,
Richa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.