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

4. Here are some class definitions with questions that follow. public class Base

ID: 3655900 • Letter: 4

Question

4. Here are some class definitions with questions that follow. public class BaseClass { // methods of BaseClass } public SomeClass extends BaseClass { // methods of SomeClass } a. SomeClass scobj = new SomeClass( ); b. BaseClass bcobj = scobj; c. SomeClass scobj2 = bcobj; d. bcobj.aMethodOfSomeClass( ); // does not exist in BaseClass A. Is statement b above legal, or is casting required? B. Statement c is trying to assign the SomeClass object referred to by bcobj to a SomeClass reference variable scobj2. What is wrong with this statement and how would you fix it. C. In statement d, a BaseClass reference is trying to access a SomeClass class method that is not part of BaseClass. Is this legal? Explain.

Explanation / Answer

A. yes, statement b is legal and no need of casting. B. You have no authority to assign the base class object directly to the child class object,so it is wrong statement.In order to fix it you have to typecast......... SomeClass scobj2 = (SomeClass) bcobj; C.you are not able to access the child class method with base class object. so this is wrong statement.

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