answersLogoWhite

0


Best Answer

TYPES OF INHERITANCE

The mechanism of deriving a new class from an old one is called inheritance. The old class is referred to as the base class and the new one is called the derived class or subclass. Inheritance is a mechanism of reusing and extending existing classes without modifying them, thus producing hierarchical relationships between them. C++ supports the following inheritance.

(a).Single Inheritance

A derived class with only one base class is called single inheritance.

#include

using namespace std;

class BaseClass {

int i;

public:

void setInt(int n);

int getInt();

};

class DerivedClass : public BaseClass {

int j;

public:

void setJ(int n);

int mul();

};

void BaseClass::setInt(int n)

{

i = n;

}

int BaseClass::getInt()

{

return i;

}

void DerivedClass::setJ(int n)

{

j = n;

}

int DerivedClass::mul()

{

return j * getInt();

}

int main()

{

DerivedClass ob;

ob.setInt(10); // load i in BaseClass

ob.setJ(4); // load j in DerivedClass

cout << ob.mul(); // displays 40

return 0;

}

(b) Multiple Inheritance

A derived class with several base classes is called multiple inheritance.

#include

using namespace std;

class Cpolygon

{

protected :

int width, height;

public:

void input_values(int one, int two)

{

width=one;

height=two;

}

};

class Cprint

{

public:

void printing (int output);

};

void Cprint :: printing (int output)

{

cout<

}

class Crectangle: public Cpolygon, public Cprint

{

public:

int area ()

{

return (width * height);

}

};

class Ctriangle: public Cpolygon, public Cprint

{

public:

int area()

{

return (width * height / 2);

}

};

int main ()

{

Crectangle rectangle;

Ctriangle triangle;

triangle.input_values(2,2);

rectangle.input_values(2,2);

rectangle.printing(rectangle.area());

triangle.printing(rectangle.area());

return 0;

}

(c) Hierarchical Inheritance

#include

using namespace std;

class student

{

protected:

int roll_no;

public:

void get_no(int a)

{

roll_no=a;

}

void put_no(void)

{

cout << "Roll No:"<

}

};

class test : public student

{

protected:

float part1,part2;

public:

void get_marks(float x,float y)

{

part1=x; part2=y;

}

void put_marks(void)

{

cout << "Marks obtained:" << "\n"

<< "Part1= " <

<<"Part2= "<

}

};

class sports : public student

{

protected:

float score;

public:

void get_score(float s)

{

score=s;

}

void put_score(void)

{

cout << "Sports wt:" <

}

};

int main()

{

sports stud;

stud.get_no(1223);

stud.get_score(6.0);

stud. display();

return 0;

}

one class may be inherited by more than one class. This process is known as hierarchical inheritance.

(d) Multilevel Inheritance

The mechanism of deriving a class from another derived class is known as multilevel inheritance.

********* IMPLEMENTATION OF MULTILEVEL INHERITANCE *********/

#include< iostream.h>

#include< conio.h>

class student // Base Class

{

protected:

int rollno;

char *name;

public:

void getdata (int b,char *n)

{

rollno = b;

name = n;

}

void putdata(void)

{

cout< < " The Name Of Student \t: "< < name< < endl;

cout< < " The Roll No. Is \t: "< < rollno< < endl;

}

};

class test:public student // Derieved Class 1

{

protected:

float m1,m2;

public:

void gettest(float b,float c)

{

m1 = b;

m2 = c;

}

void puttest(void)

{

cout< < " Marks In CP Is \t: "< < m1< < endl;

cout< < " Marks In Drawing Is \t: "< < m2< < endl;

}

};

class result:public test // Derieved Class 2

{

protected:

float total;

public:

void displayresult(void)

{

total = m1 + m2;

putdata();

puttest();

cout< < " Total Of The Two \t: "< < total< < endl;

}

};

void main()

{

clrscr();

int x;

float y,z;

char n[20];

cout< < "Enter Your Name:";

cin>>n;

cout< < "Enter The Roll Number:";

cin>>x;

result r1;

r1.getdata(x,n);

cout< < "ENTER COMPUTER PROGRAMMING MARKS:";

cin>>y;

cout< < "ENTER DRAWING MARKS:";

cin>>z;

r1.gettest(y,z);

cout< < endl< < endl< < "************ RESULT **************"< < endl;

r1.displayresult();

cout< < "**********************************"< < endl;

getch();

}

(e) Hybrid Inheritance

******** IMPLEMENTATION OF HYBRID INHERITANCE ********/

#include< iostream.h>

#include< conio.h>

class student

{

private :

int rn;

char na[20];

public:

void getdata()

{

cout< < "Enter Name And Roll No : ";

cin>>na>>rn;

}

void putdata()

{

cout< < endl< < na< < "\t"< < rn< < "\t";

}

};

class test : public student

{

protected:

float m1,m2;

public:

void gettest()

{

cout< < endl< < "Enter your marks In CP 1 And Cp 2 :";

cin>>m1>>m2;

}

void puttest()

{

cout< < m1< < "\t"< < m2< < "\t";

}

};

class sports

{

protected:

float score;

public:

void getscore()

{

cout< < endl< < "Enter your score :";

cin>>score;

}

void putscore()

{

cout< < score< < "\t";

}

};

class results : public test , public sports

{

private :

float total;

public :

void putresult()

{

total = m1+m2+score;

cout< < total;

}

};

void main()

{

results s[5];

clrscr();

for(int i=0;i< 5;i++)

{

s[i].getdata();

s[i].gettest();

s[i].getscore();

}

cout< < "______________________________________________"< < endl;

cout< < endl< < "Name\tRollno\tCP 1\tCP 2\tScore\tTotal"< < endl;

cout< < "----------------------------------------------"< < endl;

for(i=0;i< 5;i++)

{

s[i].putdata();

s[i].puttest();

s[i].putscore();

s[i].putresult();

}

cout< < endl< < "----------------------------------------------";

getch();

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

There are two types of differences, each having two different types of its own. They depend on whether you are talking about the manner in which the inheritance is made while the other type depends on the nature of the property being inherited. The manners in which inheritances are described are testate and intestate. A testate inheritance is one which comes through a decedent's will. An intestate inheritance is one that comes where there is no will and distribution of the property is made to the heirs of the decedent according to each state's laws. Every state has laws governing "intestate succession". When a person dies without a will these laws decide the how much of the decedent's property go to his heirs. The second type of inheritance depends on the nature of the property inherited and the distinction is important only when there is a will. Customary terminology stated that when a will gave real estate to a beneficiary, the gift was referred to as a devise. When personal property was given, it was referred to as a bequest. This terminology is being eliminated as a legal difference in some states as more modern probate laws are being adopted. In most states, there is no legal difference between real and personal property. Finally, just to mention these, people sometime receive real or personal property by means of joint ownership. These transfers are not "inheritances" , they are contractual transfers. Never the less, it is another way that property of a decedent is transferred to another person.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Mendelian inheritance, incomplete dominance, codominance, multiple alleles, polygenic inheritance, and sex-linked inheritance.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Morphological, Physiological, Behavioral and Sexual.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the four classification of heredity characters?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why was heredity invented?

so the genetic characters can be transmitted


Classification of dance from the Philippines?

characters


Why is the probality used in the study of heredity?

To test the significance of inherited characters in the populations


What are the four classification of letters?

The four classification of letters are size, spacing, position and thickness.


What criteria is used for modern classification?

Modern classification systems use a combination of genetic (DNA analysis), morphological (physical characteristics), and ecological (habitat and behavior) data to classify organisms into groups based on shared characteristics and evolutionary relationships. This approach helps to accurately depict the diversity of life and understand the evolutionary history of different species.


What is analogous organ classification?

http://www.tutorvista.com/content/science/science-ii/heredity-evolution/evolution-classification.phpgo there... it might help .. :]


How heredity related to genetics?

Heredity is passing the traits to offspring, means the character of parents will be passed to the children, and so on.And genetics, the gene character, they are the carriers who carry the characters of parents to the offspring.


What are the Four classification of cost?

your nan


What are the first four characters of a password?

1234 may be the first four characters of a password


What are the 4 classification of tissue in animals and humans?

The four classification of body tissues are epitheal,connective,nervous and muscle tssue. The four classification of body tissues are epitheal,connective,nervous and muscle tssue.


Linnaeus based most of his classification system on?

Linnaeus based most of his classification system on physical characteristics and reproductive structures of organisms. He classified organisms into hierarchical groups based on similarities in these features, leading to the development of the modern system of taxonomy.


What is the process by which populations slowly change over time called?