File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes please tel me how the object reference get to know that object is that type? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

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

shankar dengi
Greenhorn

Joined: Aug 09, 2008
Posts: 10
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
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40


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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
shankar dengi
Greenhorn

Joined: Aug 09, 2008
Posts: 10
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
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please tel me how the object reference get to know that object is that type?