Forums Register Login

static, super & this

+Pie Number of slices to send: Send
please give me as much examples as u can on static, super & this. try the best and simple way.i will really appreciate your help.
+Pie Number of slices to send: Send
Well, static is a little different from super and this, but I'll try to explain them all.
First of all, let's talk about static. The keyword static is generally used to refer to something that is "class specific" rather than "object specific." For example, if you define a member to be static, that member belongs to the class, rather than to any specific object of that class. Let's look at an example.

As you can see from this code, the color of each box is an instance variable. It's value is different for every instance.
The static variable numBoxesCreated, however, is often referred to as a "class variable." This member (since it is declared as static) is the same for all objects. In fact, this member exists without any objects being created at all. When you declare something as static, it belongs to the class, not to an instance of that class.
Okay, now let's look at this and super. The keyword this refers to the object you're currently in. The keyword super refers to the object that the object you're currently in inherits from.
Take this example:

By using the keywords this and super, you can explicitly refer to the object you're in or the object this object inherits from. This concept becomes increasingly useful when you're using complicated inheritance models with lots of method over-riding and shadowing.
I hope this helps a little.
If you have more specific questions, I'd be happy to help.
Corey
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
thanks corey ,really.
+Pie Number of slices to send: Send
 

Originally posted by Corey McGlone:

Take this example:

By using the keywords this and super, you can explicitly refer to the object you're in or the object this object inherits from. This concept becomes increasingly useful when you're using complicated inheritance models with lots of method over-riding and shadowing.
Corey


Hey when i compiled ur code it gave the following error

No when i declared the method doIt() as static
it gave the error

How to go ahead??
I am mighty! And this is a mighty small ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1126 times.
Similar Threads
this Refrence Problem
variable this is undefined ?
Overridden methods
question from master exam
this and super
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:18:01.