0 votes
in JAVA by

Given that Student is a class, how many reference variables and objects are created by the following code?

Student studentName, studentId;  

studentName = new Student();  

Student stud_class = new Student();   

a) Three reference variables and two objects are created.

b) Two reference variables and two objects are created.

c) One reference variable and two objects are created.

d) Three reference variables and three objects are created.

1 Answer

0 votes
by

(a) Three reference variables and two objects are created.

Reason: In the above code, there are three reference variables and two objects. The studentName, studentId, and stud_class are the three reference variables. The objects are those variables that are created using the new operator, i.e., studentName and stud_class. The studentId is only a reference variable as it is not declared using the new operator. Both studentName and stud_class are reference variables as well as objects.

Hence, there are three reference variables and two objects.

Related questions

0 votes
asked Apr 10, 2021 in JAVA by Robindeniel
0 votes
asked Apr 8, 2021 in JAVA by SakshiSharma
...