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

Write the output answers in the corresponding space//. abstract class Employee2

ID: 3582963 • Letter: W

Question

Write the output answers in the corresponding space//. abstract class Employee2 {private double data = 0.0; Employee2 (double n) {data = n;} double fun3 () {return data;} void fun4 (double n) {data = n;}} interface something1 {void fun1 (double n);} interface something2 {double fun2 ();} class Teacher2 extends Employee2 implements something1, something2 {teacher2 (double n) {super (n);}//statements A, //1. Does below statements B have any syntax error? Yes/No public void fun1 (double n) {super.fun4 (n);}//statement B, public double fun2 () {return fun3 ();}//statement C.} public class Test2 {public static void main (String [] args) {//2. Can we have below statements? Yes/No Employee2 e2 = new Employee2 (); Teacher2 t2 = new Teacher2 (20); t2.funb4 (10);//3. What is the output of below statement? System.out.println (t2.fun2 ());//statement D. t2.fun1 (40);//4. What is the output of below statement? System.out.println (t2.fun3 ());//statement E.//5. Can we add below statement and this prigram can be run? Yes/No t2.data = 3;//6. Can we add below statement and this program cabn be run? Yes/No Teacher2 t3;}}//7. Can we remove statement A and this program still can be run? Yes/No//8. Can we change statement C to below statement? Yes/No public void fun2 (double n) {data = n;}

Explanation / Answer

abstract class Employee2
{
private double data = 0.0;
Employee2(double n)
{
data = n;
}
double fun3()
{
return data;
}
void fun4(double n)
{
data = n;
}
}
interface something1
{
void fun1(double n);
}
interface something2
{
double fun2();
}

class Teacher2 extends Employee2 implements something1, something2
{
Teacher2(double n)
{
super(n);   //Statement A.
}
//1. Does below statement B have any syntax error? No.
public void fun1(double n)
{
super.fun4(n);   //Statement B.
}
/*public double fun2()
{
return fun3();   //Statement C.
}*/
public void fun2(double n)
{
data = n;
}
}

public class Test2
{
public static void main(String[] args)
{
//2. Can we have below statement? No. Employee2 is an abstract class, and cannot be instantiated.
//Employee2 e2 = new Employee2();  
  
Teacher2 t2 = new Teacher2(20);   //This will assign 20 to data.
t2.fun4(10);       //This will overwrite 10 to data.
  
//3. What is the output of below statement?   So, the statement will print 10.
System.out.println(t2.fun2());   //Statement D.  
t2.fun1(40);   //This will overwrite 40 to data.
  
//4. What is the output of below statement?   So, the statement will print 40.
System.out.println(t2.fun3());   //Statement E.
  
//5. Can we add below statement and this program can be run?  
//No. data is a private variable and cannot be assigned/accessed exclusively.
//t2.data = 3;  
  
//6. Can we add below statement and this program can be run? Yes.
Teacher2 t3;
}
}
//7. Can we remove statement A and this program still can be run. No. Thats a constructor with parameter, and is needed to do the initialization.

//8. Can we change statement C to below statement?   No, statement 2 is used in Statement D. And it cannot be void function.
/*public void fun2(double n)
{
data = n;
} */