[Message Deleted]
-
[Message Deleted]
-
[Message Deleted]
-
[Message Deleted]
If u r writing this code in C# then u must have to specify the return type for the function and this code can't run bcz u can't access the private variables even the intellisense will not show u the private members
-
[Message Deleted]
Trustapple wrote:
can anybody help me to understand private ,public functions and keywords and how they affect inheritance.....i tried a couple of codes whre i made base class method private and tried to call them and its calling just like a public method....so i think i am missing something. for example class animal { private dog() { } } class bird { private sparrow() } } class mainclass() { animal obj = new animal(); obj.dog(); } this works fine so what is the use in making the method private???? any kind of help will be appreciated
OK - 1st - get a book. Read the first few chapters, type in a few examples, then, when you get stuck post here. Your code generates at least 10 errors on compilation. Did you try it out?
class animal { private **void** dog() { } }
As somebody else said - methods need a return type.class bird { private sparrow() } }
No return type, no closing brace, not even used in Main - let's forget about this for now.class mainclass() { animal obj = new animal(); obj.dog(); }
I haven't a clue what this is about...class mainclass()
? I assume you meantstatic void Main(string[] args) { animal obj = new animal(); obj.dog(); }
Which, if you attempt to compile givesError 1 'TestApp.Program.animal.dog()' is inaccessible due to its protection level
So, private does what it says it does - it is private. NObody can see it, except from within the Animal class.Trustapple wrote:
this works fine
It doesn't really does it?
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
-
[Message Deleted]
Trustapple, I'll re-itterate my advice from umpteen times in the last week. You will learn ALL of this stuff much much better if you go and find yourself a biginner book on programming. There is no shame in doing so - we all had to start somewhere.
-
[Message Deleted]
-
And please stop deleting your messages! You have been asked politely before. We are NOT mocking you we are trying to HELP you!
I thought he might, so I copied the whole message in my reply. I doubt I will reply to any more of his posts if he won't play ball.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."