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
Which of the following is not true of the traditional approach to information processing
Which of the following hardware component is the most important to the operation of a database management system?
Large collection of files are called ____________
An audit trail ___________
If a piece of data is stored in two places in the database, then
The highest level in the hierarchy of data organization is called
One approach to standardization storing of data?
Join The Discussion