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.