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

Final Exam Secure https:llsisuinstructure.com/courses/1233754lquizzes/1197998/ta

ID: 3841894 • Letter: F

Question

Final Exam Secure https:llsisuinstructure.com/courses/1233754lquizzes/1197998/take rahool Maa M Gmail Google Doos tn LinkedIn eBay canvas I Soundcloud YouTube ia sc converter aspORTs D Question 55 1 pts public class Car Car s public static void nainXStringO args Car s1 s1.s new Caro; if Cs2.s.equalsCs1)) System.out print("1 if (s2 equalsKs1)) System.out.print 2 if Cs1.s equals(si)) Syst ten out-print 3 if Cs2.s equalsCs2)) Systen out.print 4 stetic Car goccer s) Cor gs CarO Which the result? o 124 1 followed by an exception. 12

Explanation / Answer

Hi Student,

I think the code above has a mistake in the method "go". If I compile the code as it is , I am getting a compilation error.

original program:

----------------------

public class Car{
Car s;
public static void main(String []args){
// System.out.println("Hello World");
Car s1=new Car();
s1.s=new Car();
go(s1.s);
Car s2=go(s1);
if(s2.s.equals(s1)) System.out.println("1 ");
if(s2.equals(s1)) System.out.println("2 ");
if(s1.s.equals(s1)) System.out.println("3 ");
if(s2.s.equals(s2)) System.out.println("4 ");

}
static Car go(Car s){
Car gs= Car();
gs.s=s;
return gs;
}
}

-------------------------

Output of above program is :

sh-4.3$ javac Car.java                                                                                          

Car.java:16: error: cannot find symbol                                                                          

         Car gs= Car();                                                                                         

                 ^                                                                                              

  symbol:   method Car()                                                                                        

  location: class Car                                                                                           

1 error   

========================

The syntax for the object creation in the method "go" is wrong. new keyword is not being used while creating object.

I modified the above code as below.

----------------------------------------

public class Car{
Car s;
public static void main(String []args){
// System.out.println("Hello World");
Car s1=new Car();
s1.s=new Car();
go(s1.s);
Car s2=go(s1);
if(s2.s.equals(s1)) System.out.println("1 ");
if(s2.equals(s1)) System.out.println("2 ");
if(s1.s.equals(s1)) System.out.println("3 ");
if(s2.s.equals(s2)) System.out.println("4 ");

}
static Car go(Car s){
Car gs= new Car();
gs.s=s;
return gs;
}
}

------------------------

The output for the above program is 1. Only s2.s.equals(s1) statement is true.

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