• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

An abstract class has no this instance??

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends, I got a statement - An abstract class has no this instance. (TRUE/FALSE)...

Please clear it to me.....
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which part do you not understand?

Ask yourself these questions.
1) Is it possible to create an instance of an Abstract class?
2) What does "this" refer to? Does it refer to a class? An instance? A variable?
 
sunil langeh
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Which part do you not understand?

Ask yourself these questions.
1) Is it possible to create an instance of an Abstract class?
2) What does "this" refer to? Does it refer to a class? An instance? A variable?



Dear Maneesh, thanks for quick reply, Well I know that we can't create an instance of an abstract class and this refers to current object....could you please provide and example which reflects the problem???
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see a reason, why it wouldn't have 'this' instance. My example:

 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'this' is not a instance. It is a keyword used to refer to the current object on which any non-static method was called. So you can say that it is a reference to the current object available inside non-static methods. Abstract classes have nothing to do with it...
 
sunil langeh
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:'this' is not a instance. It is a keyword used to refer to the current object on which any non-static method was called. So you can say that it is a reference to the current object available inside non-static methods. Abstract classes have nothing to do with it...


Hi Ankit , Is it mean that we can't use "this" within an Abstract class???
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sunil langeh wrote:

Ankit Garg wrote:'this' is not a instance. It is a keyword used to refer to the current object on which any non-static method was called. So you can say that it is a reference to the current object available inside non-static methods. Abstract classes have nothing to do with it...


Hi Ankit , Is it mean that we can't use "this" within an Abstract class???



You can use this in functions defined in an abstract class. When you are actually executing the code the 'this' will be referring to whatever derived concrete class the object really is at runtime.
 
sunil langeh
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Benjamin Hiner wrote:

sunil langeh wrote:

Ankit Garg wrote:'this' is not a instance. It is a keyword used to refer to the current object on which any non-static method was called. So you can say that it is a reference to the current object available inside non-static methods. Abstract classes have nothing to do with it...


Hi Ankit , Is it mean that we can't use "this" within an Abstract class???



You can use this in functions defined in an abstract class. When you are actually executing the code the 'this' will be referring to whatever derived concrete class the object really is at runtime.



Hi Benjamin, I am getting confused with - As we know that in an Abstract class there is no 'new' right?...and 'this' is invoked when class is instantiated i.e when an object is created(new classxx();)
So if we do not instantiated an Abstract class then how can be use 'this' with in it??

please correct me if i am creating little mistake or just behind the actual concept
 
Benjamin Hiner
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sunil langeh wrote:

Benjamin Hiner wrote:

sunil langeh wrote:

Ankit Garg wrote:'this' is not a instance. It is a keyword used to refer to the current object on which any non-static method was called. So you can say that it is a reference to the current object available inside non-static methods. Abstract classes have nothing to do with it...


Hi Ankit , Is it mean that we can't use "this" within an Abstract class???



You can use this in functions defined in an abstract class. When you are actually executing the code the 'this' will be referring to whatever derived concrete class the object really is at runtime.



Hi Benjamin, I am getting confused with - As we know that in an Abstract class there is no 'new' right?...and 'this' is invoked when class is instantiated i.e when an object is created(new classxx();)
So if we do not instantiated an Abstract class then how can be use 'this' with in it??

please correct me if i am creating little mistake or just behind the actual concept



You will never enter a function defined by an abstract class without first instantiating a concrete derived class. The concrete class that was instantiated is what the 'this' will refer to when you are executing the function defined in the abstract class.
 
reply
    Bookmark Topic Watch Topic
  • New Topic