Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-15-2008, 07:50 PM
Member
 
Join Date: Dec 2007
Posts: 17
feniger is on a distinguished road
abstract sub-class
is this possible in java?
abstract class A extends B () {...}
__________________
have a good one - Day I mean...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-15-2008, 09:51 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Yep,

Here is an example,

Code:
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-16-2008, 12:57 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-18-2008, 11:00 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 191
danielstoner is on a distinguished road
At any level in the class hierarchy you can declare an abstract class.

Code:
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
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-21-2008, 05:57 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by danielstoner View Post
At any level in the class hierarchy you can declare an abstract class.

Code:
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-21-2008, 09:04 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 191
danielstoner is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-21-2008, 09:10 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interface Vs Abstract Class javarishi New To Java 5 06-15-2008 07:43 AM
what is the Priority for execution of Interface class and a Abstract class Santoshbk Advanced Java 0 04-02-2008 09:04 AM
Abstract Class gapper New To Java 4 01-31-2008 03:25 PM
Abstract Class question maa11235 New To Java 1 01-06-2008 12:30 AM
Can this be done using abstract class?? romina New To Java 2 07-26-2007 11:09 AM


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