Knowee
Questions
Features
Study Tools

What will be the output of the following program?class string_class {public static void main(String args[]){String obj = "hello";String obj1 = "world";   String obj2 = obj;obj2 = " world";System.out.println(obj + " " + obj2); }}

Question

What will be the output of the following program?class string_class {public static void main(String args[]){String obj = "hello";String obj1 = "world";   String obj2 = obj;obj2 = " world";System.out.println(obj + " " + obj2); }}

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the program will be "hello world".

Here's the step by step explanation:

  1. The program starts with the creation of a class named string_class.

  2. Inside this class, a main method is defined which is the entry point of any Java program.

  3. Inside the main method, three String objects are created: obj, obj1, and obj2.

  4. obj is assigned the value "hello", obj1 is assigned the value "world", and obj2 is assigned the value of obj, which is "hello".

  5. Then, the value of obj2 is changed to " world".

  6. Finally, the program prints the value of obj and obj2 which are "hello" and " world" respectively.

So, the final output is "hello world".

This problem has been solved

Similar Questions

What will be the output of the following Java program? class mainclass { public static void main(String args[]) { char a = 'Z'; a++; System.out.print((int)a); } }Options9091122123

What will be the output of the below program?public class Test {                               public static void main(String[] args) {                                    char c = 65;                                    System.out.println("c = " + c);                               }} Note : explain clearly in the answer

What will be the output of the following Java program?class mainclass { public static void main(String args[]) { boolean ct1 = true; boolean ct2 = false; if (ct1) System.out.println(ct1); else System.out.println(ct2); } }Options10truefalse

What will be the output of the following Java program? package pkg; class output {public static void main(String args[]) {   StringBuffer s1 = new StringBuffer("Hello");   s1.setCharAt(1, x);   System.out.println(s1);   } }

e correct answerWhat is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.