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

Abstract Class?

 
sonir shah
Ranch Hand
Posts: 435
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2205
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Rob
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic