It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract Class? 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 "Abstract Class?" Watch "Abstract Class?" New topic

Abstract Class?

sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
Given the following source code, which of the lines that are commented out may be reinserted without introducing errors?

Options :
1)final void h(){} //(1)
2)BigBang(int n){m=n} //(2)
3)void k(){i++} //(3)
4)void l(){j++} //(4)
5)abstract void f(); //(0)
Correct Answer is 3)void k(){i++}
Ok, I agree with the answer.
But in addition I even feel that option 5) is right, because even if we insert the line :"abstract void f() in the class Bang, it is valid because Bang has already been declared Abstract.
Please let me know whether I am right?
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
You're right that it would be ok in class Bang, because as you pointed out, it has been declared abstract, and so the method
abstract void f();
could be uncommented.
However, if you look at the subclass of Bang, BigBang, you will see that there is no method named f(). So if you uncomment that line in Bang, you have an abstract method that is not implemented anywhere, so the compiler won't let you compile the BigBang class unless you mark it abstract. Since BingBang is already declared final in the example, and not abstract, you'd get a compiler error if you uncomment line #0.

SCJP 1.4
I agree. Here's the link:
subject: Abstract Class?
It's not a secret anymore!