asked 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.

asked
User Jin Yong
by
8.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:

answered
User Ymett
by
8.1k points
Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.