Shishir Sharma wrote:
> //U can access Derived class Private Member
> //but if u use Derived class pointer it doesn't work.
> //This is violation of object oriented concepts ...
> //Thanks
Thomas Hruska replied:
> I don't see how this is a "violation of OOP". You are asking a public
> member of the base class to execute a virtualized function - virtual
> base class functions call the most derived function of same name and
> parameters. Most implementations use a vtable...whatever address the
> function points at is the one that gets called. It seems that you are
> asking for runtime checking of sections, which would most likely result
> in a huge performance hit. If you want the function only available to
> derived classes, then it should be declared in a 'protected:' section in
> the base class. If you need it public in some classes and private in
> others, you can change the section type via a derived class. That will
> move checking of section types to compile-time and not affect runtime
> performance.
I understand Shishir feelings as the similar Java example below is refused by
the compiler. For reasons like this I prefer to program in Java whenever
possible.
class Base {
public void display () {
System.out.println ("I\'m in Base class.");
}
}
public class Derived extends Base {
private void display () {
System.out.println ("I\'m in Derived class.");
}
public static void main (String [] args) {
Base b = new Derived ();
b.display();
}
} // Derived class
[EMAIL PROTECTED]:~/Desktop/oop violation$ javac Derived.java
Derived.java:8: display() in Derived cannot override display() in Base;
attempting to assign weaker access privileges; was public
private void display () {
^
1 error
[EMAIL PROTECTED]:~/Desktop/oop violation$
____________________________________________________________________________________
Choose the right car based on your needs. Check out Yahoo! Autos new Car
Finder tool.
http://autos.yahoo.com/carfinder/
To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/c-prog/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/