File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes natr...mock Q 22 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "natr...mock Q 22" Watch "natr...mock Q 22" New topic
Author

natr...mock Q 22

madhuri vl
Ranch Hand

Joined: Jan 17, 2001
Posts: 86
1. class superclass{
2. static int i=5;
3. superclass(){
4. i++;
5. Q22();
6. }
7.
8. void Q22(){
9. i++;
10. }
11. }
12.
13. class Q22 extends superclass{
14. void Q22(){
15. super();
16. i++;
17. }
18.
19. Q22(){
20. System.out.println(" superclass constructor called "+(i++));
21. }
22.
23. public static void main(String[] args){
24. new Q22().Q22();
25. System.out.println("i = "+i);
26. }
27. }
a. Compile time error at line 4.
b. Compile time error at line 5.
c. Compile time error at line 15.
d. Compile time error at line 24.
e. Compile time error at line 25.
e. No compiler error
Answer given is c.
Can anybody explain this .Thanks in advance.

madhuri.
Ishaan Mohan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Compiler error at 15 becoz of super(). You can made call to super() or this() from a constructor only(first statement in a constructor).
void Q22()
{
super();
i++;
}

As in your code void Q22 is a function not a constructor you cannot made call to super().
madhuri vl
Ranch Hand

Joined: Jan 17, 2001
Posts: 86
oh, I haven't noticed that .
I should wide open my eyes and see. As the coding is too big we do not think about simple tricks.
Thank you .
sabyasachi mondal
Ranch Hand

Joined: Dec 26, 2000
Posts: 33
Hi Ishaan,
Is void Q22() is a function or what? Pls clarify further.
Thanks
M

Originally posted by Ishaan Mohan:
Compiler error at 15 becoz of super(). You can made call to super() or this() from a constructor only(first statement in a constructor).
void Q22()
{
super();
i++;
}

As in your code void Q22 is a function not a constructor you cannot made call to super().

madhuri vl
Ranch Hand

Joined: Jan 17, 2001
Posts: 86
Hi sabyasachi,
void 22(0 is a method and so you can not use the keyword super.
Super should be used in constructors and that too it should be the first sentence.
Hope you got it.
madhuri vl
Ranch Hand

Joined: Jan 17, 2001
Posts: 86
Hi I don't know why it appeared like that.
void Q22() is a method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: natr...mock Q 22