177k views
0 votes
Suppose a reference variable of type Integer called myInt is already declared. Create an object of type Integer with the initial value of 1 and assign it to the reference variable myInt.

User Jin Yong
by
5.2k points

1 Answer

3 votes

Answer:

//The class called "Solution" is declared

public class Solution {

//Main method which signify the beginning of program execution

public static void main(String[] args) {

//myInt variable of type Integer is declared

Integer myInt;

// An object of type Integer is declared with initial value of 1

Integer newInt = new Integer(1);

// The value of the new declared and assigned object is displayed to the user

System.out.println(newInt);

// The new declared object is assigned to the reference variable myInt

myInt = newInt;

// The value of myInt is displayed to the user

System.out.println(myInt);

}

}

Explanation:

User Ymett
by
5.1k points