Is it something like this kindly help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is it something like this kindly help

A object = new B(); // reference of class A but calling B class constructor so creating object of Class B using reference of class A. B b = (B) object; // so if we create totally b class object then we will create like B b = new B(); As we can see new B(); is already initialized in object.

7th Dec 2018, 8:38 AM
Guddu Kumar
Guddu Kumar - avatar
2 Answers
+ 3
If B is a subclass of A, then your code is fine. The comments are accurate for that code.
8th Dec 2018, 9:56 PM
John Wells
John Wells - avatar
+ 1
Yes, it is. Thanks
9th Dec 2018, 2:13 AM
Guddu Kumar
Guddu Kumar - avatar