---------- Forwarded message ----------
From: ..::ISHFAQ::.. <mc100402092@vu.edu.pk>
Date: Sat, May 7, 2011 at 3:53 PM
Subject: CS304_Example_inheritance
To: , afaaq <afaaqtariq233@gmail.com>,
In general, a well-designed class will have no public fields--everything should go through the class's functions. Functions that retrieve variables are known as 'getters' and those that change values are known as 'setters'. Since the public part of the class is intended for use by others, it is often sensible to put the public section at the top of the class.
Best Wishes,
From: ..::ISHFAQ::.. <mc100402092@vu.edu.pk>
Date: Sat, May 7, 2011 at 3:53 PM
Subject: CS304_Example_inheritance
To: , afaaq <afaaqtariq233@gmail.com>,
اسلام علیکم ورحمتہ اللہ و برکاتہ
A quick example of inheritance:class Animal { public: Animal(); ~Animal(); void eat(); void sleep(); void drink(); private: int legs; int arms; int age; }; //The class Animal contains information and functions //related to all animals (at least, all animals this lesson uses) class Cat : public Animal { public: int fur_color; void purr(); void fish(); void markTerritory(); }; //each of the above operations is unique //to your friendly furry friends //(or enemies, as the case may be)A discussion of the keywords public, private, and protected is useful when discussing inheritance. The three keywords are used to control access to functions and variables stored within a class.
public:
The most open level of data hiding is public. Anything that is public is available to all derived classes of a base class, and the public variables and data for each object of both the base and derived class is accessible by code outside the class. Functions marked public are generally those the class uses to give information to and take information from the outside world; they are typically the interface with the class. The rest of the class should be hidden from the user using private or protected data (This hidden nature and the highly focused nature of classes is known collectively as encapsulation). The syntax for public is:public:Everything following is public until the end of the class or another data hiding keyword is used.
In general, a well-designed class will have no public fields--everything should go through the class's functions. Functions that retrieve variables are known as 'getters' and those that change values are known as 'setters'. Since the public part of the class is intended for use by others, it is often sensible to put the public section at the top of the class.
protected:
Variables and functions marked protected are inherited by derived classes; however, these derived classes hide the data from code outside of any instance of the object. Keep in mind, even if you have another object of the same type as your first object, the second object cannot access a protected variable in the first object. Instead, the second object will have its own variable with the same name - but not necessarily the same data. Protected is a useful level of access control for important aspects to a class that must be passed on without allowing it to be accessed. The syntax is the same as that of public. specifically,protected:
private:
Private is the highest level of data-hiding. Not only are the functions and variables marked private not accessible by code outside the specific object in which that data appears, but private variables and functions are not inherited (in the sense that the derived class cannot directly access these variables or functions). The level of data protection afforded by protected is generally more flexible than that of the private level. On the other hand, if you do not wish derived classes to access a method, declaring it private is sensible.Best Wishes,
"...SUBHANALLAHI WABI HAMDIHI...SUBHANALLAH IL AZEEM..."
Muhammd Ishfaq
MCS 2nd Semester (PakPattan)
Muhammd Ishfaq
MCS 2nd Semester (PakPattan)
--
Remember Me In Your Prayers
Best regard's
Muhammad Afaaq
MBA 4th (Final Semester) Finance Group
Afaaq_Tariq@yahoo.com
Islamabad
For latest assignments solved quizzes files gdb solve n unsolved past papers Come join us in http://vugoogle.com
http://www.alliswell.com.pk/
http://groups.google.com/group/vustudymania
0346-5329264
If u like me than raise your hand with me
If not then raise ur standard
That's about me … !
--
Earning program links, Cell number, Websites/Groups Links, Adult contents, Spamming, Immoral & Rudish talk are strictly prohibited and banned in group.
Follow these detailed Group Rules, otherwise you will be banned at any time.
https://docs.google.com/document/d/1YJxA8x3_U7C1lRc0EXfLrJpco4A1XkB1vDxOTqOd3Jg/edit?hl=en&authkey=CNDy9tkJ
Group Email Address:
Attock-VU-Group@Googlegroups.Com
Join group by sending a blank email from University ID at:
Attock-VU-Group+Subscribe@Googlegroups.Com
Attention......!!!!!!!!!!!
Our Google Group has a problem, mostly members are facing in posting mails, If any one has this problem then forward that sending failed email at this address:
Manager.atk.grp@gmail.com
We will unsubscribe all bouncing IDs from group to resolve this issue.
Sorry for inconvenience, we have no another option for resolving this issue.
Members are requested to empty their inbox to avoid from this issue.
No comments:
Post a Comment