• Post Reply Bookmark Topic Watch Topic
  • New Topic

Abstract class extending another abstract class, Confusion!  RSS feed

 
Shashank Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
Actually I came across a weird question thrown at us by my project manager, that what if we extend an abstract class with another abstract class? What would be the result? Can their constructor could be interwoven in such a way that the object creation is not needed at all?
I tried it back home and it started yielding results, a Java developer would hate to core.
Where he was getting at, I am still clueless? Please help anyone?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It is perfectly valid to extend an abstract class, and have the subclass abstract. Heck, it is perfectly valid to extent a concrete class, and have the subclass abstract.

Don't know what you mean by "interwoven" or "started yielding results", Care to elaborate?

Henry
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what "a Java developer would hate to core" means either!
 
Shashank Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:

Don't know what you mean by "interwoven" or "started yielding results", Care to elaborate?

Henry

By interwoven, I mean that can we have such arrangement in between the two class's constructors, such that they could be triggered, if yes how (note that, both classes are abstract!). I tried using super keyword also tried declaring a static block inside the class, but of no use. Still confused.

a Java developer would hate to core

Compiler crashes! Now don't scold me for using notepad and not Eclipse or Netbeans! Please, I am well and good with textpad. IDEs look quite scary.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Failure to get constructors to work with the super( . . . ); construct suggests there might be a mistake in the design of your classes.

And you know full well that programmers love compiler error messages. They know it means a programming mistake has been caught before it got any farther.

Remember: the compiler is your friend and it only tells you off for your own good
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shashank Mittal wrote:
By interwoven, I mean that can we have such arrangement in between the two class's constructors, such that they could be triggered, if yes how (note that, both classes are abstract!). I tried using super keyword also tried declaring a static block inside the class, but of no use. Still confused.


A constructor can only call its super() as the first line of the constructor -- you will get a compiler error at any other time. Regardless, how is one constructor calling another constructor "triggered" a call? All it does is have a constructor calls its super, something that is very common. It doesn't mean that an instance is created magically.

And no, you can't call super in the static initializer.

Shashank Mittal wrote:
Compiler crashes! Now don't scold me for using notepad and not Eclipse or Netbeans! Please, I am well and good with textpad. IDEs look quite scary.


If you are able to get the compiler to core dump, then you should submit a bug report to Sun.

Henry
 
Shashank Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A constructor can only call its super() as the first line of the constructor -- you will get a compiler error at any other time.
And no, you can't call super in the static initializer.


Yeah man, I am saying I have inserted a static block inside the abstract class, and I am calling super from first line
If you are able to get the compiler to core dump, then you should submit a bug report to Sun.

Will that help?

Regardless, how is one constructor calling another constructor "triggered" a call? All it does is have a constructor calls its super, something that is very common. It doesn't mean that an instance is created magically

thats the problem man, if the abstract class can't be instantiated then at the runtime how can we make it run with the help of another abstract class, you know, the OTHERWAY! :P
Sorry If I sound way too confusing.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shashank Mittal wrote:thats the problem man, if the abstract class can't be instantiated then at the runtime how can we make it run with the help of another abstract class, you know, the OTHERWAY!


You can't instantiate an object of a class which is abstract. That's the rule. That's all. Simple, isn't it? Note that the rule isn't "You can't instantiate an object of a class which is abstract unless you have the help of some other abstract class". So this business of some other class somehow changing the rule is total nonsense. There isn't any "other way". Whatever you were told, or assumed you were told, about abstract classes extending abstract classes is total nonsense. Just go back to your book and read what it says about abstract classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!