All Exams Test series for 1 year @ ₹349 only
Question

Given the array of integers ‘array’ shown below :

1372721833911228

What is the output of the following JAVA statements ?

    int [ ] p = new int [10];

    int [ ] q = new int [10];

    for (int k = 0; k < 10; k ++)

            p[k] = array [k];

    q = p;

    p[4] = 20;

    System.out.println(array [4] + “:” + q[4]);

This question was previously asked in
UGC NET 2016 Paper 1 Question Paper (10-Jul-2016)
The correct answer is

18 : 20

In Java an array variable holds a reference to an array object. Copying elements in a loop creates independent data, while assigning one array variable to another only copies the reference, so both names then point to the same object.

Step 1 — p and q are created as two separate arrays of 10 ints. The loop copies every element of array into p, so p[4] = array[4] = 18; array and p are distinct objects.

Step 2 — q = p; makes q refer to the same object as p. The array originally created for q is no longer referenced.

Step 3 — p[4] = 20; changes the shared object, so q[4] is now 20 as well, while array[4] is untouched and stays 18.

VariableRefers toValue at index 4
arrayoriginal array18
pnew array (copy of array)18 → 20
qsame object as p after q = p20

Step 4 — The println prints array[4], then the string “:”, then q[4], giving 18 and 20 separated by the colon.

20 : 20 would need array itself to be modified, 18 : 18 would need q to be an independent copy, and 20 : 18 reverses the two values.

18 : 20 option is correct.

Was this answer helpful?

Similar Questions

  1. Which method is called first by an applet program ?

  2. Converting a primitive type data into its corresponding wrapper class object instance is called

  3. Which methods are utilized to control the access to an object in multi-threaded programming ?

  4. Which one of the following is correct ?

  5. The Servlet Response interface enables a servlet to formulate a response for a client using the method __________.

  6. In Java, when we implement an interface method, it must be declared as :

  7. Match the following interfaces of Java. Servlet package :

    List - IList - II
    a. Servlet Configi. Enables Servlets to log events
    b. Servlet Contextii. Read data from a client
    c. Servlet Requestiii. Write data to a client
    d. Servlet Responseiv. To get initialization parameters
  8. When one object reference variable is assigned to another object reference variable then

  9. It is possible to define a class within a class termed as nested class. There are _____ types of nested classes.

  10. Consider the following JAVA program :

    public class First {

        public static int CBSE (int x) {

                if (x < 100) x = CBSE (x + 10);

                return (x – 1);

            }

        public static void main (String[] args){

            System.out.print(First.CBSE(60));

        }

    }

    What does this program print ?


Important Questions from Java

  1. Arrange the following applet life cycles methods in sequence 

    A. start() 

    B. paint() 

    C. init() 

    D. stop() 

    Choose the correct answer from the options given below:

  2. A java program that is embedded in HTML document and runs in the context of java capable browser is known as ______.

  3. JAVA compiler translates source code into _______.

  4. Which of the following statement(s) is/are correct regarding java programming?

    I. Place a semicolon immediately after a method header

    II. Define a method outside the braces of a class definition

  5. The application in java, which is used for sending small applications to run at client side is __________.

Need Expert Advice?
Upcoming Exams
CTET
December 12, 2026
CBSE UGC NET
December 14, 2026
CSIR UGC NET
December 19, 2026
Test Series
UGC NET img
Teaching
UGC NET (Paper 2) 2026 Mock Test Series
796 Tests 2 Tests Free
4.4(40)
English
More Questions from UGC NET

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App