View Full Version : What is a superclass?
outdoors
October 26th, 2007, 11:41 AM
During some other research i found superclass. Suprisingly i cant find any noob information about it. What is it, what does it do and how do i use it?
Gundark
October 26th, 2007, 11:54 AM
A superclass is a class' parent class. It's the class that a class extends (inherits).
You can access the constructor of a super class by using the super() function in your classes constructor.
outdoors
October 26th, 2007, 12:00 PM
okej, that was easy. Can you give me an example when this would be useful?
And would you send arguments with super(args) or have i missunderstood?
Gundark
October 26th, 2007, 12:06 PM
Yeah, super() literally calls the superclass' constructor. So you'd need to pass all the arguments that your superclass' constructor takes.
There are plenty of times when you'd want to use this. Say you had a Point class and then extended it to create a 3 dimensional point class called Point3D. You could pass the x and y value to the superclass' constructor by doing super(x,y) in Point3D's constructor.
outdoors
October 26th, 2007, 12:23 PM
okej, I like your answers, really clear and specific. thanks alot!
Gundark
October 26th, 2007, 12:31 PM
No problem. Glad I could help!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.