What will be the output of the following Java code?
class A
{
int x;
int y;
void display()
{
System.out.print(x + ” ” + y);
}
}
class Output
{
public static void main(String args[])
{
A obj1 = new A();
A obj2 = new A();
obj1.x = 1;
obj1.y = 2;
obj2 = obj1.clone();
obj1.display();
obj2.display();
}
}
a) 1 2 0 0
b) 1 2 1 2
c) 0 0 0 0
d) System Dependent
Answer: b
Explanation: clone() method of object class is used to generate duplicate copy of the object on which it is called. Copy of obj1 is generated and stored in obj2.
Output:
1 2 1 2
Related Posts
While inserting the record into the index, if the search-key value does not appear in the index.
Insertion of a large number of entries at a time into an index is referred to as __________ of the index
In B+ tree the node which points to another node is called
A search key containing more than one attribute is referred to as a _________ search key.
Incase the indices values are larger, index is created for these values of the index. This is called
In a __________ index, an index entry appears for only some of the search-key values.
In a _______ clustering index, the index record contains the search-key value and a pointer to the first data record with that search-key value and the rest of the records will be in the sequential pointers.
Join The Discussion