• Post Reply Bookmark Topic Watch Topic
  • New Topic

difference b/w this and classname.class  RSS feed

 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
Could anyone tell me the difference b/w thisand Classname.class
letz take a java file abc.java

public class abc
{
abc()
{ new firstClass(this);
new secClass(abc.class)
}
}
howz thisand abc.class
differ in the above file ???

thanks,
raj
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do you want to know, in what context do you want to use this ? it sounds like homework....
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They're quite different. "this," called from an instance method of "abc," refers to the actual "abc" object. You can call abc methods on "this", for example.
"abc.class" is the same as Class.forName("abc"), and it refers to the java.lang.Class object which describes the abc class. You can call Class methods on abc.class.
Make sense?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!