Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following code/classes. public class A { protected int x, y; public

ID: 3925259 • Letter: C

Question

Consider the following code/classes.

public class A {

protected int x, y;

public A( ) { x = 1; y = 1;}

public int M( ) { return x * y;}

public double M( ) { return (double) x + y;}

} // end class A

public class B extends A {

protected int z;

public B( ) { z = 2; }

public int M( ) { return x – y;}

public String M( int a ) { z = a; return “GOODBYE”;}

public double M( ) { return 0.0; }

} // end class B

Precisely where does overloading occur in the code? Be sure to list all occurrences of overloading.

Where does overriding occur in the code? Be sure to list all occurrences of overriding.

Explanation / Answer

Hi, Please find my explanation.

Please let me know in case of any issue.


public class A {
   protected int x, y;
   public A( ) { x = 1; y = 1;}
   public int M( ) { return x * y;}
   public double M( ) { return (double) x + y;}
} // end class A

public class B extends A {
   protected int z;
   public B( ) { z = 2; }
   public int M( ) { return x – y;}
   public String M( int a ) { z = a; return “GOODBYE”;}
   public double M( ) { return 0.0; }
} // end class B


Hi friend there are error is both classes:
   One class can not contains same method(Duplicate):

   Calss A has :
       public int M( ) { return x * y;}
       public double M( ) { return (double) x + y;}

       these two methods are duplicate methods, they are not iverloaded. Just changing the return type, it does not means they are
       overloaded. To overload you need to change parameter list or order of parameters.

   CLass B has :
       public int M( ) { return x – y;}
       public double M( ) { return 0.0; } : duplicate methods same as A

   Any combination:

       public String M( int a ) { z = a; return “GOODBYE”;} FROM class B
       public int M( ) { return x – y;} FROM class B

       OR
       public String M( int a ) { z = a; return “GOODBYE”;} FROM class B
       public double M( ) { return 0.0; } FROM class B

       OR
       public String M( int a ) { z = a; return “GOODBYE”;} FROM class B
       public int M( ) { return x * y;} FROM class A

       OR
       public String M( int a ) { z = a; return “GOODBYE”;} FROM class B
       public double M( ) { return (double) x + y;} FROM class A


       They are overloaded

   Any combination:
       public int M( ) { return x * y;} FROM class A
       public int M( ) { return x – y;} FROM class B

       OR
       public double M( ) { return (double) x + y;} FROM class A
       public double M( ) { return 0.0; } FROM class B

       These combination are oveloaded

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote