0

I am actually studying for a final examen of my first level of OOP (we use Java), and I need to be conceptually correct in terms of OOP.

So, I have this code:

Light.turnOn(pc);
Light.turnOn(car);

Etc...

And this other one:

pc.turnOn();
car.turnOn();

I have not yet implemented the first one. The second one, I did it like this...

class pc extends Light { ... }
class car extends Light { ... }

Where Light is an abstract class. Each different class, pc and car extends from Light and they implement their own version of the method turnOn(), in each of them. In the first sample code (which I have not yet implemented), I would have different versions of the method turnOn() (in the same class), without "extending" anything.

So: which of the two codes implements/uses polymorphism? Why? How does the other example does not implement/uses it?

Thanks you in advance.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
Pablo
  • 11
  • 4
  • 1
    Please follow java naming conventions. Light.turnOn(...) implies a static method call, while pc.turnOn() implies an instance method call. But the class name is pc. This is confusing and misleading. – Andrew S Dec 11 '17 at 17:49
  • I think this question would be more useful if you put some complete code and respect coding conventions. Classes should have a name starting with an uppercase letter, you don't show the method that is overwritten and it is unclear what Light.turnOn(car) should be. If "Light" is a class, this looks like a call of a static method. – Gustave Dec 11 '17 at 17:51
  • Good luck on your final. – Michael Peacock Dec 11 '17 at 17:56
  • Hello. I said in the post that Light was an an abstract class, and the two code samples are from two different packages; I am working on them separately to see how can I implement polymorphism. – Pablo Dec 11 '17 at 18:26

0 Answers0