Ciaran Mooney wrote:My understanding is you can create a object of a parent class though the syntax Class object name = new Class();.
You create an object of a class through the syntax: ClassName variableName = new ClassName();
(It doesn't have anything to do with parent classes and objects don't have names; variables do).
Ciaran Mooney wrote:However I have no idea what the relationship is bewteen a private method declaration (or instance variable??), public declaration and a constructer function.
Words such as "public", "protected" and "private" determine from where exactly you can call methods. A method that is public can be called from anywhere. A method that is private can only be called from inside the class itself, not from methods and constructors in other classes. This allows you to hide methods inside classes. See Controlling Access to Members of a Class for more information.
A constructor is a special block of code inside your class that initializes a new instance (object) of the class. It's called when you use "new" to create a new instance of the class. A constructor is not a method. See Providing Constructors for Your Classes for more information.
Cheers for the welcome.
I will have a go at using the code tags.
Joined: Oct 13, 2005
That other class does not use a private method. It uses a public method to gain access to the private field.
I tried to add code tags, since you haven’t seen them before, but your code isn’t indented, so they wouldn’t have worked.