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

**JAVA OOP** Consider the following code: public class JavaIsGood { public stati

ID: 3595562 • Letter: #

Question

**JAVA OOP**

Consider the following code:

public class JavaIsGood {

public static void main(String[] args) {

String str = new String("I love Java!");

Object obj = str;

String n = (String)obj;

}

}

Select the option(s) that you think correspond with the code above.

Multiple answers may be correct.

1) str, obj, and n reference the same String object.

2)When casting obj to str in String n = (String)obj, an explicit casting was used.

3)When assigning str to obj in Object obj = str, a new object is created.

4)When declaring str in String str = new String(..), the String constructor is being invoked from the class String.

5)When casting obj to str in String n = (String)obj, a new object is created.

6)When casting obj to str in String n = (String)obj, the contents of obj are changed.

8)The new keyword in the line String str = new String(..), is instantiating the class String which means the same thing as creating a String object.

1) str, obj, and n reference the same String object.

Explanation / Answer

1) str, obj, and n reference the same String object.
2)When casting obj to str in String n = (String)obj, an explicit casting was used.
4)When declaring str in String str = new String(..), the String constructor is being invoked from the class String.
7)When casting obj to str in String n = (String)obj, an implicit casting was used.
8)The new keyword in the line String str = new String(..), is instantiating the class String which means the same thing as creating a String object.