TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Moose Pickard
NA
64
70.5k
Setting variable values in constructor, help
Sep 20 2010 6:34 AM
Hey
I've got this Abstract class and I want some other class to inherit from it.
abstract class Tree {
public string name;
private int age;
private int length;
public int length {
get { return length; }
set { length = value; }
}
}
class Oak: Tree {
public Oak(string name, int age, int lengthInput) {
this.name = name;
this.age = age;
length = lengthInput;
}
The problem is with setting the value of these variables in the Oak class.
this.name = name - doesn't give me errors, because I stated in the Tree class that name is public.
this.age = age - doesn't work, it says Tree.age is inaccessible due to it's protection level.
length = lengthInput - doesn't give me errors.
So If anyone can explain to me what do these things do?
I think I maybe overprotective with my variables. When should I use private keyword? At this point I have marked all private and created get/set declarations.
Thank you
Reply
Answers (
3
)
Displaying pdf file on link click
creating modules in C#