bkkothari2255 / Programming_In_Java_NPTEL

This site is to share the solution of prgramming and quiz assignment given during the Programming In java by Prof. Debasis Samantha on NPTEL.
https://bkkothari2255.github.io/Programming_In_Java_NPTEL/
83 stars 102 forks source link

missed implementing GCD interface to B Week 5 Programming Assignment Solutions 2 #4

Closed kambleaa007 closed 4 years ago

kambleaa007 commented 4 years ago

interface cant be implemented, Not overriding, its incomplete, object creation is on class, it should be interface WRONG B a = new B(); //Create an object of class B RIGHT GCD a = new B();

bkkothari2255 commented 4 years ago

@kambleaa007 Okay Fixed it.

Week 5 Programming Assignment 2

The object of Interface cannot be created, but we can create an instance of the interface as you suggesting,

GCD a = new B();

But Here we have to implement an interface GCD to class B Line 8

class B implements GCD

Thanks for Contributing.

kambleaa007 commented 4 years ago

object of Interface cannot be created is Right, Not Possible is new GCD(), But You can create REFERENCE of it, that is GCD a is possible Create object of B, new B() You can call methods using that REF, GCD a = new B(); is perfectly fine code,

This line, GCD a = new B(); three things happens here, 1) GCD a -> REFERENCE creation 2) new B() -> OBJECT creation 3) = -> ASSIGNMENT happens here

Correct me if I am wrong,

Thanks, For your time

bkkothari2255 commented 4 years ago

@kambleaa007 Yes, you are correct but here what I missed at line 8 is implementing the interface GCD which is fixed.

You talked about two bugs but there is one and you keep suggesting your approach.

  1. line 8 https://github.com/bkkothari2255/Programming_In_Java_NPTEL/blob/d5d4b0e16c0b47737369815e648123ee75c61912/Question5_2.java#L7-L8 I fixed the first bug as you asked for. So there is no requirement to solve the second.

  2. line 22 https://github.com/bkkothari2255/Programming_In_Java_NPTEL/blob/d5d4b0e16c0b47737369815e648123ee75c61912/Question5_2.java#L22 As you are suggesting here is possible, but here as per instruction in comments, we no need to do it. and if you want to do it. You can do it.

Correction is only one, there are different approaches, everyone is comfortable with their own. But majorly used one is feasible for each test case. So focus on what they wanted from your code precisely as per instructions.