JAVA CODING: (3) (10 points/2 points each) Calling super() and position of super
ID: 3753680 • Letter: J
Question
JAVA CODING:
(3) (10 points/2 points each) Calling super() and position of super() question. Find the program chess.java in the same place as the last two questions. Load it and run it. You should see this: Game constructor BoardGame constructor with i 99 Chess constructor e constructor with i - // Add your answers as comments onto the code and submit it What does the super(i) do in line 16? Comment out super (i) in the BoardGame class, the compiler complains...! Why? Without uncommenting the (super (i)) back, how will you fix it (so the compiler would not the complaint )? What does super (99) in the chess class do? Put everything back the way it was (before step 1), now move super(i) (line 16) to below the print (... ) line, the compiler complains!! Why? 1. 2. 4. 5.Explanation / Answer
1. The super(i) calls the constructor of the parent or base class.
2. It gives an error saying
"Implicit super constructor Game() is undefined. Must explicitly invoke another constructor."
This is because there is no constructor with zero arguments in the Game class.
3. Creating a no-parameter constructor in the Game class resolves the issue
4. Pass the value 99 to the BoardGame constructor which again pass to the Game constructor. The print statements of all the classes are executed.
5. An error is raised because the super keyword should be the first statement in a constructor.
Let me know if you have any queries or clarifications.... :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.