Computing.Net > Forums > Programming > Exact difference b/w a protected PU

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Exact difference b/w a protected PU

Reply to Message Icon

Name: secrets
Date: February 4, 2006 at 00:19:21 Pacific
OS: Win2000/Winxp/Linux
CPU/Ram: 1.7/256
Comment:

what is the exact difference b/w a protected and public????
please guide me as i am always confused abou it.



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: February 4, 2006 at 10:43:09 Pacific
Reply:

A protected member can be accessed by derived classes, a public member can be accessed by anybody.  Protected is actually more similar to private than public.

class Animal
{
  public GoExtinct();
  protected Reproduce();
  private Clone();
}

class Dog inherits Animal
{
  function DoAll()
  {
    }this.GoExtinct();//OK
    }this.Reproduce();//OK because we inherit from Animal
    }this.Clone();//not ok - Clone() is private
  }
}

Class Building
{
  function DoAll()
  {
    Dog d = new Dog();
    d.GoExtinct();//OK
    d.Reproduce();//Not OK because building doesn't inherit from Animal
    d.Clone();//not ok - Clone() is private
  }
}

Good luck,
-SN


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Exact difference b/w a protected PU

Diff b/w Software Developer , Sof.. www.computing.net/answers/programming/diff-bw-software-developer-sof/11482.html

Diff. b/w javascript and jscript www.computing.net/answers/programming/diff-bw-javascript-and-jscript/14428.html

CString and Character Arrays www.computing.net/answers/programming/cstring-and-character-arrays/9011.html