user3212703
user3212703

Reputation: 15

How can I extend 2 classes in Java? I need to extend JFrame plus another class

I have created a class called Gui. It needs to extend JFrame and another class called StudentDatabase.

How can I do it ?

Upvotes: 0

Views: 367

Answers (2)

dbermudez
dbermudez

Reputation: 572

You can't extend more than one class in Java.

Instead of using inheritance use composition (extend JFrame and have a member of class StudentDatabase in your class GUI).

Pass invocations of methods in GUI to its member StudentDatabase and voila...

Upvotes: 2

Clinton
Clinton

Reputation: 23145

You can't. Java doesn't allow multiple inheritance. In C++ you can do this. In Java you can implement multiple "interfaces", but you'll have to rewrite the implementations of all functions in those interfaces in your class.

Upvotes: 0

Related Questions