(The Triangle class) Design a class named Triangle that extends GeometricObject

You need to create a new Triangle object like this, so that you have a reference You also need to set it’s filled and color properties Then, you can invoke its methods like this: You’re able to access the GeometricObject‘s isFilled(), setFilled(), getColor(), and setColor() because a Triangle is a GeometricObject (extends), so it inherits all its methods. By the way, this is not how to calculate the area of a … Read more

How to call a parent class function from derived class function?

I’ll take the risk of stating the obvious: You call the function, if it’s defined in the base class it’s automatically available in the derived class (unless it’s private). If there is a function with the same signature in the derived class you can disambiguate it by adding the base class’s name followed by two colons base_class::foo(…). … Read more

cannot declare variable ‘’ to be of abstract type ‘’

The reason the base class is abstract is this pure virtual function: The derived class DisablePairCollision attempts to define that function, but it does not do it correctly: As you can see, some of the arguments have different types. E.g. colObj0 is of type const btCollisionObject*, but it should be of type const btCollisionObjectWrapper*. Therefore, … Read more

classical inheritance vs prototypal inheritance in javascript

Both the code samples you demonstrated in your question make use of prototypal inheritance. In fact any object-oriented code you write in JavaScript is a paradigm of prototypal inheritance. JavaScript simply doesn’t have classical inheritance. This should clear things up a bit: As you can see prototypal inheritance and classical inheritance are two different paradigms … Read more

Java error: Implicit super constructor is undefined for default constructor

You get this error because a class which has no constructor has a default constructor, which is argument-less and is equivalent to the following code: However since your BaseClass declares a constructor (and therefore doesn’t have the default, no-arg constructor that the compiler would otherwise provide) this is illegal – a class that extends BaseClass can’t call super(); because … Read more

Implements vs extends: When to use? What’s the difference?

extends is for extending a class. implements is for implementing an interface The difference between an interface and a regular class is that in an interface you can not implement any of the declared methods. Only the class that “implements” the interface can implement the methods. The C++ equivalent of an interface would be an abstract class (not EXACTLY the same … Read more

Inheriting constructors

If your compiler supports C++11 standard, there is a constructor inheritance using using (pun intended). For more see Wikipedia C++11 article. You write: This is all or nothing – you cannot inherit only some constructors, if you write this, you inherit all of them. To inherit only selected ones you need to write the individual constructors manually and … Read more

Inheriting constructors

If your compiler supports C++11 standard, there is a constructor inheritance using using (pun intended). For more see Wikipedia C++11 article. You write: This is all or nothing – you cannot inherit only some constructors, if you write this, you inherit all of them. To inherit only selected ones you need to write the individual constructors manually and … Read more

Difference between Inheritance and Composition

They are absolutely different. Inheritance is an “is-a” relationship. Composition is a “has-a”. You do composition by having an instance of another class C as a field of your class, instead of extending C. A good example where composition would’ve been a lot better than inheritance is java.util.Stack, which currently extends java.util.Vector. This is now … Read more