• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object class  RSS feed

 
rahul arno
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

we know that Object class super class for all class, so why we can't use reference of object class for any class object??
eg. Object obj = new Test();
here Test is sub class.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you say you can't do that? Does it give you a compiler error?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul Arno,

This is the second topic you started that has "Object class" as its subject. Please give more specific subject lines in the future.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you can only call the methods based on the reference type. Say you have an instance of a Dog, and that class has a bark() method.

If you do this:

 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the bottom line is, "you can, but why would you want to?"
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a little off the topic, but not really. some people advocate POJO's(plain old java objects) that do not (specifically) extend or implement anything. but still i have never see anyone write
Object obj = new Test();
 
Ankush Kaundal
Ranch Hand
Posts: 36
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rahul arno wrote:
we know that Object class super class for all class, so why we can't use reference of object class for any class object??
eg. Object obj = new Test();
here Test is sub class.


Rahul, there shouldn't be any problem in using reference of the Object class, can you please post the error you have faced...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!