Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 118,888 Java Programmers for FREE! Ask your question and get quick answers from experts. There are 2,070 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



extending two classes from a single class

 
Reply to this topicStart new topic

extending two classes from a single class

nila
post 3 Jul, 2008 - 01:50 AM
Post #1


D.I.C Head

**
Joined: 5 Jan, 2008
Posts: 121

Hi,
I need to extend two classes from a single class.How can i do this in a servlet

like
A class OutboundServlet extends HttpServlet should also extends AbstractManagerEventListener.How can i do this?
please assist me.

Thanks.
User is offlineProfile CardPM

Go to the top of the page


Programmist
post 3 Jul, 2008 - 02:54 AM
Post #2


Four-letter word

Group Icon
Joined: 2 Jan, 2006
Posts: 1,175



Thanked 6 times

Dream Kudos: 100
My Contributions


You can't. Java allows only single class inheritance. Classes can, however, implement multiple interfaces.

This post has been edited by Programmist: 3 Jul, 2008 - 02:54 AM
User is offlineProfile CardPM

Go to the top of the page

nila
post 3 Jul, 2008 - 03:00 AM
Post #3


D.I.C Head

**
Joined: 5 Jan, 2008
Posts: 121

Is there any other way to do this?

User is offlineProfile CardPM

Go to the top of the page

baavgai
post 3 Jul, 2008 - 03:16 AM
Post #4


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,789



Thanked 73 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


The way to do it is to write a "wrapper" class that holds objects of the type you wanted to multi inherit and exposes the methods you want from the two classes.

As stated, you can only extend one class, but implement multiple interfaces. For extra OO goodness, you can make an interface to each of the two classes and have your third class implement both. This will essentially give you the functionality you'd get from fusing the things together, anyway.

User is offlineProfile CardPM

Go to the top of the page

nila
post 3 Jul, 2008 - 03:53 AM
Post #5


D.I.C Head

**
Joined: 5 Jan, 2008
Posts: 121

how can i make an interface for a class?
User is offlineProfile CardPM

Go to the top of the page

JeroenFM
post 3 Jul, 2008 - 04:06 AM
Post #6


D.I.C Head

Group Icon
Joined: 30 Jun, 2008
Posts: 179



Thanked 9 times

Dream Kudos: 100
My Contributions


QUOTE(nila @ 3 Jul, 2008 - 03:53 AM) *

how can i make an interface for a class?


I believe the following should explain a few things

http://java.sun.com/docs/books/tutorial/ja.../interface.html
http://java.sun.com/docs/books/tutorial/ja...einterface.html
http://java.sun.com/docs/books/tutorial/ja...subclasses.html
User is offlineProfile CardPM

Go to the top of the page

nila
post 3 Jul, 2008 - 10:43 PM
Post #7


D.I.C Head

**
Joined: 5 Jan, 2008
Posts: 121

How can i create a concrete class for an abstract class using reflection.please show me in code.

Thanks
User is offlineProfile CardPM

Go to the top of the page

JeroenFM
post 4 Jul, 2008 - 01:47 AM
Post #8


D.I.C Head

Group Icon
Joined: 30 Jun, 2008
Posts: 179



Thanked 9 times

Dream Kudos: 100
My Contributions


QUOTE(nila @ 3 Jul, 2008 - 10:43 PM) *

How can i create a concrete class for an abstract class using reflection.please show me in code.

Thanks


Short answer: You can't

Long answer: Due to the ClassLoader mechanism you can't determine possible subclasses for a given class since there is no way of knowing all existing classes or obtaining them, and the java.lang.Class class therefore has no "getSubClasses" method. So using reflection, you can not determine concrete classes for an abstract class.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/13/08 03:17AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month