Free Essay

Inheritance

In:

Submitted By racketeer
Words 1146
Pages 5
Inheritance between classes
A key feature of C++ classes is inheritance. Inheritance allows to create classes which are derived from other classes, so that they automatically include some of its "parent's" members, plus its own. For example, we are going to suppose that we want to declare a series of classes that describe polygons like our CRectangle, or like CTriangle. They have certain common properties, such as both can be described by means of only two sides: height and base.

This could be represented in the world of classes with a class CPolygon from which we would derive the two other ones: CRectangle and CTriangle.

The class CPolygon would contain members that are common for both types of polygon. In our case: width and height. And CRectangle and CTriangle would be its derived classes, with specific features that are different from one type of polygon to the other.

Classes that are derived from others inherit all the accessible members of the base class. That means that if a base class includes a member A and we derive it to another class with another member called B, the derived class will contain both members A and B.

In order to derive a class from another, we use a colon (:) in the declaration of the derived class using the following format:

class derived_class_name: public base_class_name
{ /*...*/ };

Where derived_class_name is the name of the derived class and base_class_name is the name of the class on which it is based. The public access specifier may be replaced by any one of the other access specifiers protected and private. This access specifier limits the most accessible level for the members inherited from the base class: The members with a more accessible level are inherited with this level instead, while the members with an equal or more restrictive access level keep their restrictive level in the derived class. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 | #include <iostream>using namespace std;class CPolygon{protected: int width,height;public: void setValue(int w,int h) { width=w; height=h; }};class CRectangle : public CPolygon {public: void Area() { cout << width * height << endl; } };class CTriangle : public CPolygon {public: void Area() { cout << width * height / 2 << endl; }};void main (){ CPolygon pol; pol.setValue(10,12); //cout << pol.height //hatalı. CRectangle rec; rec.setValue (4,2); CTriangle tri; tri.setValue(4,2); rec.Area(); tri.Area();} | 8 4 |

The objects of the classes CRectangle and CTriangle each contain members inherited from CPolygon. These are: width, height and set_values().

The protected access specifier is similar to private. Its only difference occurs in fact with inheritance. When a class inherits from another one, the members of the derived class can access the protected members inherited from the base class, but not its private members.

Since we wanted width and height to be accessible from members of the derived classes CRectangle and CTriangle and not only by members of CPolygon, we have used protected access instead of private.

We can summarize the different access types according to who can access them in the following way: Access | public | protected | private | members of the same class | yes | yes | yes | members of derived classes | yes | yes | no | not members | yes | no | no |

Where "not members" represent any access from outside the class, such as from main(), from another class or from a function.

In our example, the members inherited by CRectangle and CTriangle have the same access permissions as they had in their base class CPolygon: 1
2
3
4
5 | CPolygon::width // protected access CRectangle::width // protected access CPolygon::set_values() // public access CRectangle::set_values() // public access |

This is because we have used the public keyword to define the inheritance relationship on each of the derived classes: | class CRectangle: public CPolygon { ... } |

This public keyword after the colon (:) denotes the most accessible level the members inherited from the class that follows it (in this case CPolygon) will have. Since public is the most accessible level, by specifying this keyword the derived class will inherit all the members with the same levels they had in the base class.

If we specify a more restrictive access level like protected, all public members of the base class are inherited as protected in the derived class. Whereas if we specify the most restricting of all access levels: private, all the base class members are inherited as private.

For example, if daughter was a class derived from mother that we defined as: | class daughter: protected mother; |

This would set protected as the maximum access level for the members of daughter that it inherited from mother. That is, all members that were public in mother would become protected indaughter. Of course, this would not restrict daughter to declare its own public members. That maximum access level is only set for the members inherited from mother.

If we do not explicitly specify any access level for the inheritance, the compiler assumes private for classes declared with class keyword and public for those declared with struct.
What is inherited from the base class?
In principle, a derived class inherits every member of a base class except: * its constructor and its destructor * its operator=() members * its friends

Although the constructors and destructors of the base class are not inherited themselves, its default constructor (i.e., its constructor with no parameters) and its destructor are always called when a new object of a derived class is created or destroyed.

If the base class has no default constructor or you want that an overloaded constructor is called when a new derived object is created, you can specify it in each constructor definition of the derived class:

derived_constructor_name (parameters) : base_constructor_name (parameters) {...}

For example: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 | // constructors and derived classes #include <iostream> using namespace std; class mother { public: mother () { cout << "mother: no parameters\n"; } mother (int a) { cout << "mother: int parameter\n"; } }; class daughter : public mother { public: daughter (int a) { cout << "daughter: int parameter\n\n"; } }; class son : public mother { public: son (int a) : mother (a) { cout << "son: int parameter\n\n"; } }; int main () { daughter cynthia (0); son daniel(0); return 0; } | mother: no parameters daughter: int parameter mother: int parameter son: int parameter |

Notice the difference between which mother's constructor is called when a new daughter object is created and which when it is a son object. The difference is because the constructor declaration ofdaughter and son: 1
2 | daughter (int a) // nothing specified: call default son (int a) : mother (a) // constructor specified: call this |

Similar Documents

Free Essay

Inheritance Law

...Inheritance Law in Belgium and Switzerland Marieke Martens We live, we work and we die. People basically work to make money and spend it but also save it. After somebody has died what will happen to the money and the possessions? Firstly the division of the money and possessions takes place, according to the will. But what if there is now will? If there is a will or not, the possessions and money will not be inherited for free. The inheritance law is a collection of articles, which explains what happens to and with the inheritance of the person who died when there is no will and when there is a will. In this paper two countries will be compared based on their inheritance law. The first country is Belgium, which is part of the EU and has no specific advantages if it comes to being a tax paradise. The other country, which will be used in this research, is Switzerland, which is not part of the EU and is very famous for being a tax paradise. Both countries do have one thing in common: they are both West-European countries. Because Switzerland is a tax paradise it can be assumed that the inheritance law in Switzerland is more favourable than in the Belgium. This statement basically states that in Switzerland you have to pay less inheritance tax, there are better condition if it comes to making wills or not, than in Belgium, which results in a higher inheritance than in Belgium. These are the fields of Inheritance law that will be covered in the paper in order to answer he...

Words: 4021 - Pages: 17

Free Essay

Inheritance Tax (Iht)

...Inheritance Tax (IHT) Name Course Institutional Affiliation Date 1. Introduction Inheritance tax (IHT) is the tax paid when one’s property, money or possession is transferred to another person. It was introduced through the Inheritance Act of 1984, and it came into effect in the United Kingdom in 1986. IHT replaced the successor tax to estate duty, that was known as Capital Transfer Tax. However, the inheritance tax is considered less important because of its insignificant contribution to the United Kingdom’s economy, which is, in most cases, less than 1% of the total tax collected. Despite this, it is important for people who are likely to have a significant potential liability to pay inheritance tax, which is paid after the death of the property owner. Thus, it has been popularly renamed “Death Tax”. The tax is also charged on specific gifts that are executed during an individual’s lifetime. Moreover, the tax is charged to a person whose net worth exceeds £325,000. This paper focuses on an overview of how the inheritance tax operates in the UK, and discusses some strategies that can be applied to reduce the potential liability of IHT, as well as the merits and demerits of such strategies. 2.0. Overview of the Inheritance Tax Regime in the United Kingdom 2.1. How Inheritance Tax Operates in the UK Inheritance tax is that duty charged on the transfer of wealth, especially when a person dies. It is sometimes...

Words: 3043 - Pages: 13

Free Essay

Inheritance

...Sex chromosomes produce very unique patterns of inheritance in living organisms. In humans, there is an X chromosome and a Y chromosome that determines the sex of the offspring. A male has an X and Y chromosome, whereas a female has two X chromosomes. The sex of an offspring is determined by whether the sperm cell that fertilizes the egg is made up of an X or a Y chromosome; ultimately the male is the determining factor of the sex of the offspring. Even though the Y chromosome determines if the offspring will be male, the X chromosome has genes that control certain human characters; these genes are called sex-linked genes because they are linked to a certain sex. There are approximately 1,098 sex-linked genes that code unusual inheritance patterns other than the female sex trait. Some of these sex-linked genes carry unusual inheritance such as color blindness, Duchenne muscular dystrophy and hemophilia. (O’Neil, 2012). In the case of the recessive mutation that causes hemophilia, a female has to be the carrier of the mutated allele, since she has the X chromosomes only. If the female carrier of the disease mates with a male who has hemophilia (XhY), there would be a one-quarter chance that they would produce a female offspring that has hemophilia (XhXh). Males though are more susceptible to inheriting the hemophilia trait if the mother is a carrier, because the dominant gene (XH) will prevent the disease. (Simon, 2015). Since males can only have an X and a Y chromosome, there...

Words: 1135 - Pages: 5

Free Essay

Disqualification Under Mitakshara Law

...Session:2011-2016 FAMILY LAW “ Disqualification as to succession under Mitakshara law” Acknowledgement I am very thankful to everyone who all supported me for I have completed my project effectively and moreover on time. I am equally grateful to my criminal law faculty: Mr. S.s.. He gave me moral support and guided me in different matters regarding the topic. He had been very kind and patient while suggesting me the outlines of this project and correcting my doubts. I thank him for his overall supports. Last but not the least, I would like to thank my friends who helped me a lot in gathering different information, collecting data and guiding me from time to time in making this project despite of their busy schedules ,they gave me different ideas in making this project unique. Thanking you Contents ACKNOWLEDGEMENT 2 INTRODUCTION 3 The Hindu Succession Act: Divergence from tradition 4 PROVISIONS OF SUCCESSION UNDER HINDU SUCCESSION ACT 5 LAWS OF DISQUALIFICATIONS 7 SUGGESTIONS : 13 CONCLUSION 14 BIBLIOGRAPHY 15 Introduction Succession under Hindu Law ‘Succession’ implies the act of succeeding or following. It implies the transmission or passing of rights from one to another.  In every system of law provision has to be made...

Words: 5227 - Pages: 21

Free Essay

Willis

...In reviewing the situation we know that the Notimelefts have a net estate of $8,500,000 and three children. The goals are: to cover their own needs; pass funds on to three children equally; avoid taxes; protect their funds; keep their business private; and give no money to charities. The issues here are: will the Priest be allowed to have an inheritance or would it be given to the church (which looks like a charity to Willis and Wanda); would Darlene’s manipulating husband spend the money and what would happen in the case of divorce; what about possible grandchildren (does Ohno have a sibling?); and when Derelict is in prison would his inheritance be required to pay restitution? What happens if Willis or Wanda are incapacitated? The first thing I would advise would be to open a Revocable Living Trust for Willis (Trust A), one for Wanda (Trust B), and a Children’s trust with a spend-thrift clause to keep Derelict from spending his inheritance foolishly. Trust funds up to $5,120,000 are excluded from estate taxes so I would fund Wanda’s trust to that amount, and fund Willis’ trust with the rest. This would give them lower estate taxes because they would not be paying on the total amount. These trusts will avoid probate when the time comes which is a concern of Wanda and Willis. I would list the children’s trust as the beneficiary to Willis’ and Wanda’s trusts upon their deaths. Wanda and Willis are still alive and we do not know of any life-threatening diseases...

Words: 324 - Pages: 2

Free Essay

Costitutional Validity of Various Provisions of Hindu Succession Act

...CONSTITUTIONAL VALIDITY OF VARIOUS PROVISIONS OF THE HINDU SUCCESSION ACT,1956 INDEX: INTRODUCTION__________________________________________________________________ ARE PERSONAL LAWS REALLY LAWS? _______________________________________________ ARE PERSONAL LAWS SUBJECT TO PART III OF THE CONSTITUTION? _______________________ TYPES OF SUCCESSION___________________________________________________________ WHO IS A HINDU?_______________________________________________________________ BEFORE HINDU SUCCESSION ACT__________________________________________________ INTRODCUTION TO HINDU SUCCESSION ACT, 1956____________________________________ CONSTITUTIONAL VALIDITY OF: 2005 AMENDMENT…………………………………………………………………………………………………………………. SECTION 6, HSA………………………………………………………………………………………………………………………….. SECTION 7, HSA………………………………………………………………………………………………………………………………… SECTION 14, HSA…………………………………………………………………………………………………………………………….. SECTION 15 &16, HSA…………………………………………………………………………………………………………………….. OPINION_________________________________________________________________________ CONCLUSION______________________________________________________________________ INTRODUCTION: Through this paper, I want to analyse the constitutional validity of various provisions of the Hindu Succession act, 1956 , which is a personal law applicable to Hindu citizens of India. I have attempted to briefly explain how the flaws in the said act pose a constitutional challenge and have also tried arriving...

Words: 5545 - Pages: 23

Premium Essay

Estate Planning for Same Sex Couples

...Estate Planning for Same Sex Couples I. Introduction The benefits of marriage are unavailable to same-sex couples. Moreover, outdated intestacy statutes fail to recognize the close family bond between same-sex partners. Moreover, most intestacy laws discriminate against same-sex couples in that gay or lesbian relationships are generally considered invalid for the purposes of distributing the estate of a deceased partner who dies without a will. Accordingly, in order to reap inheritance and tax benefits that are automatically afforded to traditional married couples, these same-sex couples must rely on extensive and creative legal planning. There are several tools that provide solutions to this issue. Contract based estate planning techniques are the most commonly used tools for distributing a decedent’s property at death. Though the following planning mechanisms provide certain advantages, they are also accompanied by various disadvantages. II. Wills A will is an instrument by which a person directs dispositions of property to take effect upon death. It is the only document that allows a decedent’s probate assets to pass testate to persons of his or her choosing as opposed to passing via the strict laws of intestacy, under which the surviving partner would receive nothing. Even in the presence of strategies used to avoid probate such as intervivos trusts, wills are an essential precautionary measure to demonstrate the intent to pass property outside of probate, to...

Words: 2337 - Pages: 10

Premium Essay

Natural vs Supernatural

...Joshua Clarke Prof. Bisla ENG 333 5.8.2014 How Natural is the Supernatural Horace Walpole's The Castle of Otranto makes frequent use of supernatural effects. The novel's uses of the supernatural are a perfect example of its predecessor status as the first gothic novel, as well as question the purpose for all of its supernatural occurrences. Is it God punishing those deserving of the sentence? Or is it all just a very big coincidence and in our characters’ imagination? Most of the supernatural incidents in the novel are directed towards the themes of succession and inheritance. They revolve around the issue of establishing the rightful heir to the seat of Otranto. Because of the murderous actions of his grandfather Don Ricardo, who poisoned the previous rightful owner Alfonso the Good, the current prince Manfred has ruled over the region contrary to the precepts of genealogical law. In fact, many of the ghostly occurrences relate to exposing the usurper Ricardo before establishing Theodore, the rightful heir, onto the throne. The apparitions are portrayed in a bizarre and exaggerated manner, allowing the story to take on a rather surreal, unbelievable route where it is safe to say that spiritual vengeance is being exacted on those “got away with it”. This is apparent in the opening scene, when Manfred discovers that his only son has been crushed to death under a giant helmet which appears to have fallen out of the sky. It would later be discovered that the helmet is similar...

Words: 689 - Pages: 3

Free Essay

Thomas Paine

...obtained easily and esteemed too lightly. We see in some of these episodes where individuals and couples squander through millions of dollars in short periods of times. They find themselves bankrupt and in more turmoil than when they did not have the extravagant means upon winning a lottery. If these individuals had worked hard for their money it would have meant more to them. Earning their means could have prevented them from squandering through millions of dollars. I know a young man who lost his parent tragically when he was ten years old. He inherited a very large sum of money. The inheritance was not set up in a trust fund that required him to wait until he had learned life’s values of earning what you have. This young man received his inheritance at the tender age of 18 with the only requirement being that he graduates high school to be eligible to collect this inheritance. Upon turning 18, he went on lavish vacations, purchased a new truck, boat...

Words: 627 - Pages: 3

Premium Essay

Miss

...lead. He was however, incredulous by the fact that this may not be achieved in the future of the perfect society. To this fact he gives an ingenious riposte, such societies will be under the guardianship of the offspring of the current guardians. That means what the future society will be under the guardianship of a not skill but the benefits of inheritance. In such a society, dissatisfaction is possibly the way of the day. Plato maintained that for dissatisfaction an understanding of the nature of the human being is the answer. That is, people are naturally different and they have where they fit in the society (Philosophyprofessor). In such a situation, they will be able to rule the society. A perfect society, I believe, is one that is distinctive by leaders who have the interests of the society at hand. That is, a society under the reign of guardians who are in favor of the members of the society and their needs. A society that is simply having rulers who have inherited power is liable to doom. This is because, in most cases, such kinds of people not only lack the wisdom to rule, but they are also corrupted by the benefits of inheritance that they become nefarious with power. However, in a situation where someone who has inherited power is able to stand for the wishes of the people then can lead a perfect society. The wishes of the governed should the guiding factor here. It defines what the society stands for and what it aims to...

Words: 356 - Pages: 2

Premium Essay

Huguette Clark Estate Case Study

...I appreciate the opportunity to advise you regarding this inheritance case. To ensure a complete understanding between us, I am stating the pertinent information about the advice that I will be rendering and the facts I have gathered. The law imposes various outcomes that shows how you are the rightful heirs to the late Huguette Clark estate. Querela This is the process that I would recommend that we use Since you would naturally succeeded Ms. Clark under the ius civile as sui herdes if she would have died intestate. Then under testamentary you should have succeeded Ms. Clark also. Exherdatio Since under law the person making the will have to list all disinherited male and female suis by name. Skipping any names of potential heirs could lead...

Words: 844 - Pages: 4

Premium Essay

Pros And Cons Of Residuary Estate

...Also, the residuary estate includes all specific gifts that failed or lapsed. To plan your residuary estate in the will, you would list a residuary beneficiary to inherit all the remaining property. Otherwise, the remaining property would default to the estate. Typically, sound estate plans will have a residuary clause in the will listing a residuary beneficiary. 2) Guardian for minor children - Although guardians aren’t really beneficiaries, they could be handling the inheritance of a minor child. Appointing guardians is possible only by the will. 3) Property that can’t have designated beneficiaries – In some states, property such as vehicles and personal accounts don’t allow ways to designate beneficiaries for the property. As a result, the property must pass through the will to listed beneficiaries. 4) Heirlooms and specific gifts of personal property – If you have heirlooms or personal property you want to give to a specific person, then list that person as a...

Words: 452 - Pages: 2

Free Essay

Land Related Challenges to Slum Upgrading

...LAND SUCCESSION IN KENYA: THEORY AND PRACTICE By Ronald Matende Omwoma (BA, MA, Dip, LA) A private Land Administration Expert Paper presented to Institution of Surveyors of Kenya (ISK) South Rift Seminar on Saturday 24th October, 2015 at NAC 1.0: Introduction 1.1: Background The Kenya National Land Policy notes that ‘land can be acquired through inheritance which entails, testate or intestate succession’ (GOK, 2008). It further noted that majority of Kenyans rarely follow the succession act, and instead transmission of land rights upon death is undertaken within customary and religious systems which discriminate against children and women. Such systems also rarely leads to legal and documented land tenure security, hence further complicating the chances of the future generations to access secure land. Many Kenyans perceive the legal land succession process as tedious, complex, inaccessible and expensive. This has made the majority of Kenyans to live on land for which they don’t have a title. The government and other stakeholders in land have for some time now been pre-occupied with finding ways of making the land succession process easier, cheaper and more accessible to the majority of Kenyan especially those living in rural areas. In the National Land Policy the government undertook to: 1. Sensitize and educate Kenyans on the provisions of the law of succession Act; 2. To expedite the application of the law of succession Act; and 3. To require that...

Words: 9089 - Pages: 37

Free Essay

Willis & Wanda

...Business Law – 312 Carol Parker October 31, 2012 Willis and Wanda Notimeleft Estate Plan In reviewing the situation we know that the Notimelefts have a net estate of $8,500,000 and three children. The goals are: to cover their own needs; pass funds on to three children equally; avoid taxes; protect their funds; keep their business private; and give no money to charities. The issues here are: will the Priest be allowed to have an inheritance or would it be given to the church (which looks like a charity to Willis and Wanda); would Darlene’s manipulating husband spend the money and what would happen in the case of divorce; what about possible grandchildren (does Ohno have a sibling?); and when Derelict is in prison would his inheritance be required to pay restitution? What happens if Willis or Wanda are incapacitated? The first thing I would advise would be to open a Revocable Living Trust for Willis (Trust A), one for Wanda (Trust B), and a Children’s trust with a spend-thrift clause to keep Derelict from spending his inheritance foolishly. Trust funds up to $5,120,000 are excluded from estate taxes so I would fund Wanda’s trust to that amount, and fund Willis’ trust with the rest. This would give them lower estate taxes because they would not be paying on the total amount. These trusts will avoid probate when the time comes which is a concern of Wanda and Willis. I would list the children’s trust as the beneficiary to Willis’ and Wanda’s trusts upon their deaths...

Words: 727 - Pages: 3

Premium Essay

Retirement and Estate Planning

...Name Tutor Course Date Final Exam 2016 1. A trust is a legal agreement document that must be drawn up by an attorney. 2. The creator of a trust is called settlor or grantor.  3. The individual or a business entity who administers the trust is a called a trustee and has attorney powers.  4. A trust can be living or testamentary.  5. A beneficiary who is to receive the income of the trust for life has equitable interest in the trust. 6. When a trust terminates the assets of the trust will be distributed to the correct beneficiaries who are named in the trust document. 7. A trust created during the lifetime of the individual is a living trust while   a trust created at the death of the individual is a testamentary trust. 8.  Is a trust subject to federal income tax?  Yes and if so what tax form would be filed? Trust and Estate Tax Return. 9.  If an individual wanted to control his or hers assets after they died they would have established through their living trust a will. 10.  This type of trust  declaration would allow the individual to avoid probate but would  still be subject to  taxation by federal estate tax . 11.  A gift qualifying for the annual exclusion must be $14000 or less and be a present interest gift. 12.  The person making the gift is the donor and the person receiving the gift is the donee. 13. If an individual makes a  taxable gift they must file a tax report on money above the annual gift exclusion...

Words: 1379 - Pages: 6