Skip to content
Advertisement

Tag: inheritance

Printing String Attribute Inherited from SuperClass shows Null

I am extending a class and using the super keyword to in my subclass constructors. However, when I attempt to print the inherited attribute String. It returns null } So when I create a TrueFalseQuestion object and call its getQuestion() method, I get output: null True/False? Why is it not printing the question I passed when creating the object? How

Why can’t I add a type parameter to an overriding method?

I need to implement a method from a class Foo, in my subclass Bar: As you can see, my method would benefit from a type parameter: (I could also use raw types because I know it’ll work, but everything I’ve read says you really shouldn’t do that) Unfortunately, this is illegal – my method foo in Bar “clashes with foo()

Composition or Inheritance for classes with almost similar implementations but different input and outputs for methods?

I have the following classes, which have quite similar method implementations. Only the classes’ method inputs and outputs seem to be of different types. When I put it like this, it sounds like a case for inheritance, however, the fact that the inputs and outputs are different and are related to two lambdas, make me wonder if they should remain

Advertisement