• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need to Extend two methods  RSS feed

 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I need to extend two methods:

public class MyClass extends javax.swing.JFrame implements PropertyChangeListener{
public class MyClass extends lib.BasePageInline

How do I do this?

thanks,
Michele
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michele,

Can you please mention your correct requirement please?
As per my assumption, you want to ask how to extend two classes and not methods? right?

If thats the case let me tell you that it is not possible since multiple inheritance is not supported in java.
You need to make use of Interfaces for the same.

Kindly go through some java tutorials for Inheritance and Interfaces concepts it will be helpful for you.

Thanks and Regards,
---------------------------------------------------------------------------------------
Ashwini Kashyap | akashyap@infocepts.com | www.infocepts.com
---------------------------------------------------------------------------------------
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I understand what you have said, thanks for reminding me regarding the same.

However, my question could be extended to something such as Request.Dispatcher method

Do you know how to use it so that I can creatively extend the methods into the one class, thanks,

Michele
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, folks don't use the phrase "extend methods". You either extend a class, or you can implement or override a method. but 'extending a method' just doesn't make sense.

If you are asking "how can I extend two classes?" - you can't.

 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michele Smith wrote:
However, my question could be extended to something such as Request.Dispatcher method

Do you know how to use it so that I can creatively extend the methods into the one class, thanks,

Michele



I am trying to understand your requirement but unable to do so. Can you please form sentence in such a way that I am able to get through.
"Extending the methods" is wrong question actually hence it will be beneficial if you explain your requirement clearly may be I can help.

Thanks and Regards,
---------------------------------------------------------------------------------------
Ashwini Kashyap | akashyap@infocepts.com | www.infocepts.com
---------------------------------------------------------------------------------------
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good points. I meant extend classes.

I have a problem on this code now:



I instantiated this at the end of my existing servlet, after the instantiation of the image:



I wondered, why would the lines

System.out.println and
rd.include(request.response)

be erroring out?

Thanks,
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did this, do you think it will work?

No errors

 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michele, I think the problem is in including image with include() . I dont think it will work.
Basically, include() method of RequestDispatcher includes the content of the requested resource (any of them jsp, servlet, html, etc) on the server response.

Also as I said before you cant extend multiple classes but you can implement multiple Interfaces so proceed with that.

Thanks and Regards,
---------------------------------------------------------------------------------------
Ashwini Kashyap | akashyap@infocepts.com | www.infocepts.com
---------------------------------------------------------------------------------------
 
Joe Areeda
Ranch Hand
Posts: 334
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwini is correct multiple inheritance is not possible in Java BUT it's rarely if ever needed.

Besides using interfaces you can also use a member class. Just instantiate or pass the 2nd class and make the call from inside.

The big advantage of an interface is calling code can refer to the interface and use any class that implements it but you can't use it with library classes that are already defined.

Joe
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!