• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

If A is a class..den what will A.class return??

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if A is a class.... what is A.class??? and if aa is an object of class A....den what will aa.class return?? A.class is returning "class A" ... but what is dis class?? is it a variable in Object class? what is the relaton between Class & Object class??
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very disturbing question...not exact but some related stuff

We have A.java as a source file having a public class "A" and "aa" as A's object. When you compile A.java, you get A.class. Every class is a subclass of Object.
----
Now if you print A.class in A.java , it comes as "class A"
If you try to get "aa.class" , its a compiler error as "aa" isnt a class!
----
We have a class java.lang.Class (extends Object).Instances of the class j.l.Class represent classes and interfaces in a running Java application.
j.l.Class objects are constructed automatically by the Java Virtual Machine as classes( like A.class) are loaded and by calls to the defineClass method in the class loader.

----
refer Class Loaders and java.lang.Class to understand more and post here if you get the exact answer.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A.class represents the java.lang.Class of Class A.

If aa is an object of A and if you want to get the Class to which aa is an object, use aa.getClass(). It returns the same java.lang.Class.

A.class and aa.getClass(), both Upon printing prints the class name in a readable manner along with the package name.


aa doesn't have an attribute called class. So aa.class won't compile.
 
This tiny ad will self destruct in five seconds.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic