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

NFO2313 513 Spring 2018 Quiz 2 ID: Childjava Tester java ie clas Parent public c

ID: 3736156 • Letter: N

Question

NFO2313 513 Spring 2018 Quiz 2 ID: Childjava Tester java ie clas Parent public class Child extends public class Testor Parent vold func 1(intx) System.out.printin("in F1% public void func2(char c) System.out printinÇ'in F2") public void func30 System.out printinin F3): public static void func40 System.out.printin("in F4") public static void main(String args) public void func1(int x) System. out printnC'n B1) P public void func2(double d) System.out.printin'in 82") public void func50 System.out printin("'in B5") public statie void tunc4o Parent p new Parento: Child c new Child0; HERE! B5 System.out.printin('in B4") Q2: (13 Points) Consider each expression below as appearing at the HERE! in file Tester java, and write either "error" if the expression won't compile, or write the output that the resulting function call would produce. A. p.func1(38); J. func40: B. cfunc1 (38); C. p.func2(A)X K. Parent.func40: L. p.func50 M. Child-func4(); D. c.func2(A_ E. p.func2(1.8) F. c.func2(1.8) G. p.func30): H. c.func30 I. c.func50

Explanation / Answer

Output is given below and rest all are errors

class Parent{
public void func1(int x)
{
System.out.println("In F1");
}
public void func2(char c)
{
System.out.println("In F2");
}
public void func3()
{
System.out.println("In F3");
}
public static void func4()
{
System.out.println("In F4");
}
}

class Child extends Parent{
public void func1(int x)
{
System.out.println("In B1");
}
public void func2(char c)
{
System.out.println("In B2");
}
public void func5()
{
System.out.println("In B5");
}
public static void func4()
{
System.out.println("In B4");
}
}

class Main{
public static void main(String[] args)
{
Parent p = new Parent();
Child c = new Child();
  
// A B C D
System.out.print("A. ");
p.func1(38);
System.out.print("B. ");
c.func1(38);
System.out.print("C. ");
p.func2('A');
System.out.print("D. ");
c.func2('A');
  
/*E F : NO suitable method found error because 1.8 is a float which can't be converted to character
p.func2(1.8);
c.func2(1.8);
*/
  
// G H I
System.out.print("G. ");
p.func3();
System.out.print("H. ");
c.func3();
System.out.print("I. ");
c.func5();
  
/* J: func4 is not a method in the current class. So, throws an error.
func4();
*/
  
// K
System.out.print("K. ");
Parent.func4();
  
/* L : Not a static method to call like that. It has to be instantiated to call.
p.func5();
*/
  
// M
System.out.print("M. ");
Child.func4();
  
}
}

/*OUTPUT
In F1
In B1
In F2
In B2
*/

Output is given below and rest all are errors

  A. In F1  B. In B1  C. In F2  D. In B2  G. In F3  H. In F3  I. In B5  K. In F4  M. In B4

class Parent{
public void func1(int x)
{
System.out.println("In F1");
}
public void func2(char c)
{
System.out.println("In F2");
}
public void func3()
{
System.out.println("In F3");
}
public static void func4()
{
System.out.println("In F4");
}
}

class Child extends Parent{
public void func1(int x)
{
System.out.println("In B1");
}
public void func2(char c)
{
System.out.println("In B2");
}
public void func5()
{
System.out.println("In B5");
}
public static void func4()
{
System.out.println("In B4");
}
}

class Main{
public static void main(String[] args)
{
Parent p = new Parent();
Child c = new Child();
  
// A B C D
System.out.print("A. ");
p.func1(38);
System.out.print("B. ");
c.func1(38);
System.out.print("C. ");
p.func2('A');
System.out.print("D. ");
c.func2('A');
  
/*E F : NO suitable method found error because 1.8 is a float which can't be converted to character
p.func2(1.8);
c.func2(1.8);
*/
  
// G H I
System.out.print("G. ");
p.func3();
System.out.print("H. ");
c.func3();
System.out.print("I. ");
c.func5();
  
/* J: func4 is not a method in the current class. So, throws an error.
func4();
*/
  
// K
System.out.print("K. ");
Parent.func4();
  
/* L : Not a static method to call like that. It has to be instantiated to call.
p.func5();
*/
  
// M
System.out.print("M. ");
Child.func4();
  
}
}

/*OUTPUT
In F1
In B1
In F2
In B2
*/