Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inhertence of abstract ()

 
Netty poestel
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Question is :-Given the following source code, which of the lines that are commented out may be reinserted without introducing errors?

one of the factors given in the explanation is:-

abstract void f( ) ; //(0)
"If this line is inserted, then class BigBang will have to be declared abstract. "

Is this a fact , that if a class extends a class with a abstract (),it must itself be declared abstract ?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you uncomment that line (//0) there is no implementation of the method in class Bang. So BigBang would have to implement it. But BigBang does not, so BigBang has to be declared abstract. But then we have a contradiction: BigBang is final and cannot be declared abstract! The final prevents BigBang being extended and method f from being provided with an implementation.
 
Netty poestel
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx. Barry.
this was my cue [qoute] "So BigBang would have to implement it"
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are actually two issues with uncommenting this line. Do you see them both?

//BigBang(int n) { m = n } //(2)
 
Netty poestel
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I do see that it'll no longer have a def. constructor that's used in the main().
Thx
 
Pavan Kumat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can uncomment following line without any problems -
//void k(){ i++; } //(3)

Can-not uncomment following line since ; is missing -
//BigBang(int n) { m = n } //(2)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic