Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. [Message Deleted]

[Message Deleted]

Scheduled Pinned Locked Moved C#
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Trustapple
    wrote on last edited by
    #1

    [Message Deleted]

    L N M J 5 Replies Last reply
    0
    • T Trustapple

      [Message Deleted]

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      obj.dog() is private, you cannot call it. the compiler throw an error. if you make it public, then you can call it. private : can only be called inside that class. public : can also be called outside that class.

      1 Reply Last reply
      0
      • T Trustapple

        [Message Deleted]

        N Offline
        N Offline
        Nouman Bhatti
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • T Trustapple

          [Message Deleted]

          M Offline
          M Offline
          Malcolm Smart
          wrote on last edited by
          #4

          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 meant static 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."

          1 Reply Last reply
          0
          • T Trustapple

            [Message Deleted]

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            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.

            --- How to get answers to your questions[^]

            1 Reply Last reply
            0
            • T Trustapple

              [Message Deleted]

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #6

              And please stop deleting your messages! You have been asked politely before. We are NOT mocking you we are trying to HELP you!

              --- How to get answers to your questions[^]

              M 1 Reply Last reply
              0
              • J J4amieC

                And please stop deleting your messages! You have been asked politely before. We are NOT mocking you we are trying to HELP you!

                --- How to get answers to your questions[^]

                M Offline
                M Offline
                Malcolm Smart
                wrote on last edited by
                #7

                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."

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups