---
title: "Java Multiple Inheritance"  
description: "Java Multiple Inheritance"  
author: "Samuel Fernandes"  
published: 2014-11-05  
updated: 2014-11-05  
canonical: https://www.mindstick.com/forum/2519/java-multiple-inheritance  
category: ".net"  
tags: ["javafx", "inheritance"]  
reading_time: 2 minutes  

---

# Java Multiple Inheritance

I am working with the JavaFX Shape subclasses, and I have run into what I believe is a rather strange issue. My goal is to extend several of these shape subclasses (i.e. Rectangle, Circle) in order to add my own [attributes](https://www.mindstick.com/articles/13105/2-attributes-that-make-your-odoo-ecommerce-theme-productive-and-engaging) to these objects. For example, the [extension](https://www.mindstick.com/articles/22/extension-method) of the Rectangle subclass would look like this:

```
public class MyRectangle extends javafx.scene.shape.Rectangle
    implements SpecialInterface {

    private SpecialAttributes specialAttributes;
}
```

Where the SpecialInterface can be used to specify the [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) related to the new attributes that will be added to MyRectangle and MyCircle, in this case:

```
public interface SpecialInterface {

    public SpecialAttributes getSpecialAttributes();
    public void setSpecialAttributes();

}
```

However, when I try to create [service](https://www.mindstick.com/articles/105963/online-thesis-writing-service-for-college-kids-with-disabilities) classes that [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php) these subclasses of Rectangle and Circle, it seems as though I cannot do so generically. Essentially, the problem arises when I need to utilize attributes and methods from both the Shape subclasses and the SpecialInterface [interface](https://www.mindstick.com/articles/12101/interfaces-in-java-extending-interfaces):

```
public class ManipulationService{

    public ManipulationService(<Undefined> myExtendedShape) {
        myExtendedShape.onRotate(new EventHandler<>(){
        });

        myExtendedShape.getSpecialAttributes();
    }

}
```

The issue here is that I cannot create a superclass for my extended shapes that would [replace](https://yourviews.mindstick.com/view/81330/cow-antibody-research-in-usa-a-step-ahead-to-replace-plasma-therapy) <Undefined> above. Specifically, if I create a superclass, I cannot extend the specific shapes that I want to extend in my subclasses due to a lack of [multiple inheritance](https://www.mindstick.com/forum/159471/how-does-c-plus-plus-support-multiple-inheritance-and-what-are-potential-issues-associated-with-it). If I replace <Undefined> with Shape, though, I then lose access to the methods in SpecialInterface.

I'm sure that this sort of multiple-inheritance problem has been solved before, but I cannot find the solution. I appreciate any and all suggestions on how to handle this situation.

## Replies

### Reply by Anonymous User

You can define ManipulationService like this:

```
class ManipulationService<T extends Shape & SpecialInterface> {
    public ManipulationService(T myExtendedShape) {
        myExtendedShape.onRotate(/* ... */);
        myExtendedShape.getSpecialAttributes();
    }
}
```


---

Original Source: https://www.mindstick.com/forum/2519/java-multiple-inheritance

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
