1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
zheka24 [161]
4 years ago
11

Explain the concepts o f polymorphism, Encapsulation, Inheritance in detail with suitable examples?

Computers and Technology
1 answer:
levacccp [35]4 years ago
8 0

Answer:

Encapsulation:-It is the binding of the data and functions so that they works as one unit.

Inheritance:-When one class acquires the property of another class it is called inheritance.

Polymorphism :-It generally means more than one form

Explanation:

Encapsulation:- class is an example of encapsulation it can hold different data types and functions in a single container called class.

class Name{

public:

string first_name;

string last_name;

void Display()

{

cout<<first_name<<" "<<last_name<<endl;

}

};

Inheritance:-The property of a class acquiring the properties of another class is called inheritance.

Now we will inherit the above defined class.

class person: public Name

{

public:

char gender;

int age;

void Display()

{

cout<<first_name<<" "<<last_name<<gender<<age<<endl;

}

};

int main()

{

Name n;

person p;

n.Display();

p.Display();

}

Polymorphism- There are two types of polymorphism:-

1.Run time polymorphism=The values are decided at run time.

2.Compile time polymorphism=The values are decided at compile time.

Example:-In the above example we have function Display() in both the classes.This is an example of compile-time polymorphism. We are deciding at the time of compilation which display to use.

You might be interested in
Write a C program to calculate and display the coordinates of midpoint - M of a linesegment between two given points - say A and
pychu [463]

Answer:

//Program in C.

// header file

#include <stdio.h>

#include <math.h>

// main function

int main(void) {

   // variables

float x1,y1,x2,y2;

float s,xm,ym,d;

// ask to enter x coordinate of A

printf("Enter coordinate (x) of point A:");

// read x1

scanf("%f",&x1);

// ask to enter y coordinate of A

printf("Enter coordinate (y)  of point A:");

// read y1

scanf("%f",&y1);

// ask to enter x coordinate of B

printf("Enter coordinate (x) of point B:");

//read x2

scanf("%f",&x2);

// ask to enter y coordinate of B

printf("Enter coordinate (y) of point B:");

// read y2

scanf("%f",&y2);

// calculate Midpoint of A and B

xm=(x1+x2)/2;

ym=(y1+y2)/2;

// calculate slope of the line

s=(y2-y1)/(x2-x1);

// calculate Distance between two points

d=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));

// print result

printf("Midpoint of both the point is: %f %f",xm,ym);

printf("\nSlope of both the line is: %f",s);

printf("\nDistance between both the point is: %f",d);

return 0;

}

Explanation:

Read the x & y coordinates of both the points.Then calculate the Midpoint of both the and assign it to variables "xm"&"ym".Then calculate the slope of the line and assign it to variable "s".Then find the distance between the two points and assign it to variable "d".Print all these results.

Output:

Enter coordinate (x) of point A:2

Enter coordinate (y) of point A:3

Enter coordinate (x) of point B:9

Enter coordinate (y) of point B:8

Midpoint of both the point is: 5.500000 5.500000

Slope of both the line is: 0.714286

Distance between both the point is: 8.602325

6 0
3 years ago
Which of the following will increase the level of security for personal and confidential information on a mobile device if the d
Soloha48 [4]
I believe is a and c.
8 0
3 years ago
Write a static method named listcountriesoforigin, to be added to the bowl class, which is passed an array of bowl objects, and
melomori [17]
<span>I guess, this is java. Try that code:
public static String listCountriesOfOrigin (Bowl[] bowls) {
</span>for(int i = 0; i < bowls.length; i++) {<span> String origin = bowls[i].getOrigin();
</span><span>System.out.println(origin)</span><span>; }
}</span>
7 0
4 years ago
What is the process of analyzing data to extract information not offered by the raw data alone? data mart analysis data mining d
ludmilkaskok [199]
The answer is data mining. Hope this helps. :)
3 0
4 years ago
Write a Java code statement for each of following:
Naddik [55]

Answer:

double decimal1, decimal2;

int whole;

Explanation:

Required

Declare 2 decimals and 1 int.

The syntax to declare a variable is:

<em>data-type variable-name;</em>

To declare decimal, we simply make use of double or float data types.

So, we have:

double decimal1, decimal2; ----> for the decimal variables

And

int whole; ---- for the whole number

6 0
3 years ago
Other questions:
  • ________ is the presentation of information to the user and the acceptance of the user’s commands. a.data storageb.data access l
    7·1 answer
  • What type of wireless connection requires an unobstructed "line of sight" between transmitter and receiver?
    8·1 answer
  • Which key is used to indent the first line of a paragraph to the right?
    15·2 answers
  • Which tool is used to plan a web site?<br> HTML<br> Storyboard<br> Text editor<br> WYSIWYG
    5·2 answers
  • You want to verify whether a PTR record exists for the Serv2.csmpub.local host, but you don't know the IP address. Which of the
    8·1 answer
  • If a fuse block or holder has tree fuses, it may be termed a...
    7·1 answer
  • If you forget your privacy password what will you do if the ask this question what is the name of one of your teacher?​
    12·1 answer
  • Es costoso construir un robot
    6·1 answer
  • Hlo Brainlians !!
    11·2 answers
  • USPS stuck on "We are preparing your order for shipment" for 3 days. What does this mean?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!