aspose file tools
The moose likes Beginning Java and the fly likes Abstract class extending another abstract class, Confusion! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Abstract class extending another abstract class, Confusion!" Watch "Abstract class extending another abstract class, Confusion!" New topic
Author

Abstract class extending another abstract class, Confusion!

Shashank Mittal
Greenhorn

Joined: Nov 30, 2009
Posts: 9
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?


Lord don't move that mountain, Give me the strength to climb it.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16815
    
  19


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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

I don't know what "a Java developer would hate to core" means either!


[Jess in Action][AskingGoodQuestions]
Shashank Mittal
Greenhorn

Joined: Nov 30, 2009
Posts: 9
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
Sheriff

Joined: Oct 13, 2005
Posts: 32833
    
    4
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

Joined: Sep 28, 2004
Posts: 16815
    
  19

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

Joined: Nov 30, 2009
Posts: 9

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
Bartender

Joined: Oct 14, 2005
Posts: 16487
    
    2

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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Abstract class extending another abstract class, Confusion!
 
Similar Threads
Abstract
overriding concrete methods with abstract ones
Abstract class question
Abstract, Interfaces!
Abstract classes and Interfaces