nus-cs2113-AY2021S2 / forum

5 stars 0 forks source link

Java Exercises (Week 4 Exercise 3) #26

Closed LeeHanYongAndy closed 3 years ago

LeeHanYongAndy commented 3 years ago

Can I clarify if this is intended?

In Circle.Java and Rectangle.Java, line 1 was written as "public class Circle implements Shape{" and "public class Rectangle implements Shape{".

Was the use of "implements" intended as I could not get my program to produce the expected output unless I change the implement to extends.

Hemrish commented 3 years ago

Extends

I believe we have to use "implements" if we are accessing an interface method and use "extends" to access a class. So since Circle is a class, extends should be used here. Not sure tho.

LeeHanYongAndy commented 3 years ago

Extends

I believe we have to use "implements" if we are accessing an interface method and use "extends" to access a class. So since Circle is a class, extends should be used here. Not sure tho.

Yes, I have googled it as well. You're absolutely correct on using "implements" for interfaces. Similarly, I believe that it should be "extends" since it's referring to a superclass but I'm lost too haha.

okkhoy commented 3 years ago

This is an oversight on my part. I did not remove the implements from the template.

For this one,

  1. If you wish to continue with implements, please make Shapean interface(Interfaces are covered in Week 5 material).
  2. If not, you can change implementsto extendsand make Shapea class.

in both cases, the polymorphic behavior of the area method is apparent.

LeeHanYongAndy commented 3 years ago

This is an oversight on my part. I did not remove the implements from the template.

For this one,

  1. If you wish to continue with implements, please make Shapean interface(Interfaces are covered in Week 5 material).
  2. If not, you can change implementsto extendsand make Shapea class.

in both cases, the polymorphic behavior of the area method is apparent.

Hi Professor, Understood. Thank you for the clarification! 👍🏼