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

PLEASE READ CAREFULLY! 1. Given the program below. One block of the program is m

ID: 3815547 • Letter: P

Question

PLEASE READ CAREFULLY!

1. Given the program below. One block of the program is missing. There are 4 sets of candidate code can go in there. What will be the output from each set of candidate code?

Candidate code

Output

b.m1();

c.m2();

a.m3();

c.m1();

c.m2();

c.m3();

a.m1();

b.m2();

c.m3();

a2.m1();

a2.m2();

a2.m3();

2.

Type this program and save it as MonsterTest_firstInitialLastName.java (remember, the class name must be change accordingly for me to be able to run your program).

Fill the missing code section and produce the following output:

*** output***

a bite?

breath fire

arrrgh

*** end of output

*/

Your job is to take items from the pool and place them into the blank lines in the code. You may use the same item more than once, and you might not need to use all the items. Your goal is to make a set of classes that will compile and run together as a program. Save your program as Rowboat_firstInitialLastName.java before you compile and run the program.

Pool: rowboat, Sailboat, subclasses, Boat, testboats, extends, return, int len, drift, hoist sail, continue, int length, String, stroke Natasha, rowTheBoat, movem setLength, public, getLength, void, int, static, private, int b1, int b2, int b3, b1, b2, b3, length, break, len

Candidate code

Output

b.m1();

c.m2();

a.m3();

c.m1();

c.m2();

c.m3();

a.m1();

b.m2();

c.m3();

a2.m1();

a2.m2();

a2.m3();

2.

class A int ivar 7; void ml System, out. rintln. A's ml, void m2 System.out rintln "A's m2, i void m3 System.out ("A's m3, i class B extends A void m1 System.out ("B's ml, class C extends B void m3 System. out. rintln. ("C's m3, (ivar 6)) public class Mixed2 public static void main (String args) A a new A B b new B CC new CO A a2 new CC) The candidate code goes here what is the output of each set of candidate code? justify your answers

Explanation / Answer

Here is the code explained as comment for problem 1:

public class Mixed2
{
    public static void main(String[] args)
    {
       A a = new A();
       B b = new B();
       C c = new C();
       A a2 = new C();
       b.m1();  
       //b is an instance of B, and has a member m1().
       //So, that m1() a local method to B will be called.
       //And the output is: B's m1,
      
       c.m2();
       //c is an instance of C, but doesn't have a member m2().
       //So, the parent class A member m2() will be called.
       //And the output is: A's m2.
      
       a.m3();
       //a is an instance of A, and has a member m3().
       //so, that m3() a local method to A will be called.
       //And the output is: A's m3,
      
       c.m1();
       //c is an instance of C, but doesn't have a member m1().
       //So, the parent class B member m1() will be called.
       //And the output is: B's m1,
      
       c.m2();
       //c is an instance of C, but doesn't have a member m2().
       //And the parent class B still doesn't have a member m2().
       //So, the parent of B i.e., class A member m2() will be called.
       //And the output is: A's m2.
      
       c.m3();
       //c is an instance of C, and has a member m3().
       //So, that m3() a local method to C will be called.
       //And the output is: C's m3, 13
      
       a.m1();
       //a is an instance of A, and has a member m1().
       //so, that m1() a local method to A will be called.
       //And the output is: A's m1,
      
       b.m2();
       //b is an instance of B, but doesn't have a member m2().
       //So, the parent class A member m2() will be called.
       //And the output is: A's m2,
      
       c.m3();
       //c is an instance of C, and has a member m3().
       //So, that m3() a local method to C will be called.
       //And the output is: C's m3, 13
      
       a2.m1();
       //a2 is an instance of C, but doesn't have a member m1().
       //So, the parent classB member m1() will be called.
       //And the output is: B's m1,
      
       a2.m2();
       //a2 is an instance of C, but doesn't have a member m2().
       //And the parent class B still doesn't have a member m2().
       //So, the parent of B i.e., class A member m2() will be called.
       //And the output is: A's m2.
      
       a2.m3();
       //a2 is an instance of C, and has a member m3().
       //So, that m3() a local method to C will be called.
       //And the output is: C's m3, 13
    }
}

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