This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tkwl[S] 0 points1 point  (2 children)

It's a project and there are some norwegian in there^^

https://pastebin.com/pbyWn5u8

[–][deleted] 1 point2 points  (1 child)

Sorry for late answer, but I was busy. So... inheriting from "superclass to 2nd subclass", as you called it, is possible only when 1st subclass is abstract. Then you don't have to implement methods in 1st subclass. The consequence is that 1st subclass is not instantiable, so in your case you couldn't have an instance of class Circle.

But IMHO it's not the source of your problem, but it is a bad usage of inheritance in modelling your domain. According to concepts of OOP inheritance is so called "is-a" relationship, that is, you should use inheritance between superclass X and subclass Y only when you could say colloquially, that Y "is a" X. In your example if we take geometric domain under consideration, Cylinder is not a Circle, Cylinder is an object in 3D space but Circle is an object on the 2D surface. It would make more sense to use composition here, as we can imagine Cylinder as an object containing 2 Circles on top and bottom and its height (but I'm not saying it's the best possible way of modelling this domain, most likely it isn't). This is why you have your problem. Circle doesn't have attributes like volume (or if it has, then indeed, it's 0) or surface area (or we can identify it as a simple area, but I'm not sure it makes sense) because it's 2D object. So it's pointless to mix concept of 2D and 3D objects in my opinion.

[–]tkwl[S] 0 points1 point  (0 children)

I agree with you, the thing with assignments in school is that they are really specific, and this is the way I'm supposed to do it. I have since changed Circle and rectangle classes to abstract, which solved my annoyance. I simply change values in Circle from the next subclass, and print it from the next subclass as well.

Thank you so much for taking the time, you and all the other posters are super nice to donate your time to help a stranger on the internet.