|
|
|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

05-15-2008, 07:50 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 17
|
|
|
abstract sub-class
is this possible in java?
abstract class A extends B () {...}
__________________
have a good one - Day I mean...
|
|

05-15-2008, 09:51 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
Yep,
Here is an example,
public class test extends B{
public test(){
this.printA();
this.printB();
}
public static void main(String args[]){
new test().printA();
}
}
abstract class B extends A{
public void printA(){
System.out.println("class B");
}
}
abstract class A{
public void printB(){
System.out.println("class A");
}
}
Guess the output....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-16-2008, 12:57 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
|
|
feniger got a nice example. 
As that example, you have keep in mind two things.
1. Abstract class can be subclassed, as you can see.
2. Abstract classes cannot instantiate. If you do such a things, in compile time, got an error that abstract class cannot be instantiate.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-18-2008, 11:00 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Canada
Posts: 191
|
|
At any level in the class hierarchy you can declare an abstract class.
package jf.acls;
public class Concrete {
@Override
public String toString() {
return "Concrete";
}
}
package jf.acls;
public abstract class Abstract extends Concrete {
@Override
public String toString() {
return "Abstract extends Concrete";
}
public abstract int getTheNumber();
}
__________________
Daniel @ [ To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. ]
Language is froth on the surface of thought
|
|

05-21-2008, 05:57 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
|
|
Originally Posted by danielstoner
At any level in the class hierarchy you can declare an abstract class.
package jf.acls;
public class Concrete {
@Override
public String toString() {
return "Concrete";
}
}
package jf.acls;
public abstract class Abstract extends Concrete {
@Override
public String toString() {
return "Abstract extends Concrete";
}
public abstract int getTheNumber();
}
Nice explanation though. I have one confusion here. What you mean any level of class hierarchy. I'm confusing it with your code. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-21-2008, 09:04 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Canada
Posts: 191
|
|
I think his question was if it is possible to extend a concrete class (non-abstract) with an abstract class. And I said yes Abstract extends Concrete. I just wanted to make it clear that an abstract class can exist lower in the hierarchy, not only at the top. I hope it is clear now  because if I continue to explain it will become really messy and unclear. LOL
__________________
Daniel @ [ To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. ]
Language is froth on the surface of thought
|
|

05-21-2008, 09:10 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
|
|
|
Sure, I got the point. Thanks.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
All times are GMT +3. The time now is 10:55 AM.
|
|
VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org