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

can please anyone help with these question? NAME Csc 162 Hwy H5 inheritance (lec

ID: 3807478 • Letter: C

Question

can please anyone help with these question?

NAME Csc 162 Hwy H5 inheritance (lecs.11Parts & 2) 1. Is the following statement valid or invalid. Lf in tell why if (Circle) yourobject getRadius() 00 2. Circle the line(s) that give compile-timeerrors for the following program I WH public interface B public void displayO: public class DI f public class D2 implements B public void display() System out.println("D2'); public class D3 implements B public void display() System out println( D3'); public class Tester public static void main(String [largs) B b; b new DIO b display(); b new D20): b display(): b new D30): b display();

Explanation / Answer

Hi, I have answered firsr two Questions: Q1, Q2.

Please repost other in separate post.

Please let me lnow in case of anh issue in first two.


1)
  
   if((Circle)yourObject.getRadius() >= 0)

   This is invalid statement.

   Because, this : (Circle)yourObject.getRadius() means:

       first callinf getRadius() method on yourObject
       then typecasting returned value of : yourObject.getRadius()
       to Circle.

       it should be: ((Circle)yourObject).getRadius()

2)
   B is a interface

   D1 is a class

   D2 is a class that implements interface B

   D3 i a class that implements B


   Yes. THere is errors in Tester class.

   D1 class not implementing B

   so, b = new D1() is invalid.


  

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