Bookmark Topic Watch Topic
  • New Topic

please tel me how the object reference get to know that object is that type?

 
shankar dengi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
please tel me how the object reference get to know that object is that type?
please tel me depth of object reference ...
 
Henry Wong
author
Marshal
Pie
Posts: 22094
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator

All objects have a header, that among other things, include info on the class type -- and super, interfaces, etc. So, during assignment to a reference, the type is checked, and if incorrect, throws an exception.

Henry
 
shankar dengi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
Henry Wong wrote:
All objects have a header, that among other things, include info on the class type -- and super, interfaces, etc. So, during assignment to a reference, the type is checked, and if incorrect, throws an exception.

Henry

Joined: Aug 09, 2008
Posts: 8

[Post New]posted Yesterday 9:13:25 PM
Quote Edit
class Display
{
void display()
{
System.out.println("hi");
}
}
class Disp1 extends Display
{
void disp1()
{
System.out.println("hi1");
}
}
class

{
public static void main(String [] arg)
{
Display b=new Disp1();
Disp1 a=new Display();

}
}
in this example "b" reference check the header of type disp1 and it matches disp1 type so it compiles fine even "a" reference can point to both disp1 and display and object is display so it should compile but it fails why ?
please explain me detail?
 
Henry Wong
author
Marshal
Pie
Posts: 22094
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
shankar dengi wrote:
in this example "b" reference check the header of type disp1 and it matches disp1 type so it compiles fine even "a" reference can point to both disp1 and display and object is display so it should compile but it fails why ?
please explain me detail?


If this is the jist of your question, then this topic is a duplicate. Please don't double post... use the other topic as that already received a response.

http://www.coderanch.com/t/502342/java/java/please-help-out-object-reference

Henry
 
    Bookmark Topic Watch Topic
  • New Topic