This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What happens when you want to extend to 2 different classes  RSS feed

 
Andrew Cleland
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am quite new to Java, and have been constructing a servlet, which works until I add some new functionality.

This new functionality just so happens to be a bunch of code I have copied from somewhere else. The copied code works fine in its own context. But the problem I have is that my servlet extends HttpServlet, and the copied code has a method from a different class, which was implemented in the original source as extends x.

The problem being that I can't extend 2 different classes, what is the way to tackle this problem?

Andrew
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could create an instance of x and call its appropriate methods.
 
Andrew Cleland
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,

I was in the process of composing another message saying I did not understand what you meant, when I looked at the code again, and figured out what to do, from your suggestion. It now works.

Thank you.

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