What is the output of the following JAVA program? class Test { public static void main (String [ ] args) { Test obj = new Test (); obj.start (); } void start () { String stra="do”; String strb = method (stra); System.out.print(“:” + stra + strb); } String method (String stra) { stra=stra+”good”; System.out.print (stra); return “good”; } }

What is the output of the following JAVA program? class Test { public static void main (String [ ] args) { Test obj = new Test (); obj.start (); } void start () { String stra="do”; String strb = method (stra); System.out.print(“:” + stra + strb); } String method (String stra) { stra=stra+”good”; System.out.print (stra); return “good”; } } Correct Answer dogood : dogood

The correct answer is option 4.

Key Points

[ alt="F1 Raju.S 29-04-21 Savita D8" src="//storage.googleapis.com/tb-img/production/21/04/F1_Raju.S_29-04-21_Savita_D8.png" style="width: 358px; height: 249px;">

Test class initiates the object. And call the start function, 'stra' stores 'do' and 'strb' waits for the value for returning method function. After the control moves to the method function(). And it concatenates the value of 'stra' and prints 'dogood'. Finally, the method returns a 'good' start function. 
∴ Hence the correct answer is dogood : do good.

Related Questions

What will be the output when the following program is compiled and executed? abstract class TestAbstract{ String my_name; String myName(){ my_name = "Examveda"; return my_name; } abstract void display(); } public class Test extends TestAbstract{ void display(){ String n = myName(); System.out.print("My name is "+ n); } public static void main(String args[]){ Test t = new Test(); t.display(); } }