Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating objecct

 
Saumyaraj Zala
Ranch Hand
Posts: 65
AngularJS Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PLEASE PROVIDE REASON ABOUT THE ERROR

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error? And please KeepItDown
 
changu mani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
During compile time, compiler is not aware of what kind of object ob is pointing to. So it is necessary to do external casting.
Do this way, the compiler error goes away.

Sub ob1= (Sub)ob;
Abc ob2=(Abc)ob;
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
changu mani wrote:During compile time, compiler is not aware of what kind of object ob is pointing to. So it is necessary to do external casting.
Do this way, the compiler error goes away.

Sub ob1= (Sub)ob;
Abc ob2=(Abc)ob;


The first line is legal. The second will give ClassCastException at runtime.
 
Niranjan Aithal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
changu mani wrote:During compile time, compiler is not aware of what kind of object ob is pointing to. So it is necessary to do external casting.
Do this way, the compiler error goes away.

Sub ob1= (Sub)ob;
Abc ob2=(Abc)ob;


Looks like you read: public class Sub extends Abc
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic