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

Assume that a definition of class Automobile has a composite object called my En

ID: 3555322 • Letter: A

Question

Assume that a definition of class Automobile has a composite object called my Engine. Also assuembers of class Engine me the all the data members of class Engine that contain information about the engine such as displacement, horspower, torque, etc. Are all private data members of the engine class. wirte the function prototype that would be required for an object of class Automobile to acces the dtat member horspower of my engine object. Explain your answer, including what kind of a function this is, what class it would be definedin, what its attribute is, why is necessary.

Explanation / Answer

class Engine { private int displacement = 4; } public class { public static void main(String[] args) throws Exception { Field myEngine = Engine.class.getDeclaredField("displacement"); myEngine.setAccessible(true); myEngine.get(new Engine()); System.out.println("myEngine.displacement"); } }

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