super is used to call constructor from the parent class.
this refer to the variables or methods from the same class from which
the object is created.
To be more precise:
For example:
class Media extends Entertainment{
int size;
public TV(double regularPrice, String manufacturer, int size)
{
super(regularPrice, manufacturer);
this.size = size;
}
}
..............
......
In main method
{
Media m= new Media();
Media m1= new Media();
m.TV(100,XYZ, 300);
m1.TV(300,abc,400);
}
So now the object "m" will hold the size=300
and m1 will hold the size as 400
So when you use " this" keyword for variable each object will have
its own state for variable size like 300, 400, etc.
But if you dont use " this " keyword for variable all object created
will have same state.
In the above example the size will be 400 for object m1 as well as m.
I hope my understanding is correct, If it is wrong please correct me.
Can anyone tell me whether the keyword super can be used to call
methods from the parent class .
On Sun, Feb 22, 2009 at 11:26 PM, Jon Carlson <[email protected]> wrote:
> Hi all, I just had a question about the use of the "super" keyword in the
> lab as used below:
>
>
>
> public TV(double regularPrice,
>
> String manufacturer,
>
> int size) {
>
> super(regularPrice, manufacturer);
>
> this.size = size;
>
> }
>
>
>
> I was wondering if someone could explain how the "super" and "this" lines of
> code is being applied and what their purpose is. I understand generally
> what it is they are doing, but it is slightly confusing. Thanks ahead of
> time.
>
>
>
> Jon Carlson P.E.
>
> Engineering Director
>
> CC Technics, Inc.
>
> 253-250-1600 cell
>
> 253-473-9295 office
>
> 253-476-2712 fax
>
> [email protected]
>
> www.cctechnics.com
>
>
>
> DISCLAIMER:
>
> This message is confidential, intended only for the named recipient(s) and
> may contain information that is privileged or exempt from disclosure under
> applicable law. If you are not the intended recipient(s), you are notified
> that the dissemination, distribution or copying of this information is
> strictly prohibited. If you received this message in error, please notify
> the sender then delete this message.
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---