+ 1
What does this (ABC) mean in this code?
I dont understand the use of (ABC) in the following code. public static void main() throws CloneNotSupportedException Abc obj = new Abc(); Obj.i = 5; Obj.j=6; Abc obj1 = (Abc) obj.clone();
2 RĂ©ponses
+ 4
ABC is a type of object. When you clone an object of type ABC, the program forgets what type of object the clone is, so you CAST it to type ABC using the parenthesis.
+ 1
You should have got that by now, Abc is a class or in general a data type.
Abc obj1 = (Abc) obj.clone();
Here you are down casting obj and converting it to type Abc because the clone() is derived from the Object class and any object cloned by default will have Object class reference so you need to cast it to a type you want to work with or create object of.