Computer Science, asked by bhumikaM2080, 1 year ago

What is class ? How does it accomplish data hiding ? Explain with an example?

Answers

Answered by satya1502
0
class is a group of objects ..
Answered by Anonymous
3

Class

A class is a collection of objects which share certain characteristics and behaviour . A class is a composite datatype since it uses several datatypes within it .

A class hides data by restricting to the curly braces in which it is declared

Here is an example :

class sum

{

void main()

{

int a=4;

int b=6;

int c=a+b;

System.out.println("Sum="+c);

}

}

Now lets see another class :

class add

{

void main()

{

System.out.println(c);

System.out.println("Loser");

}

}

Now this class if written just after the first one will show an error.

Cannot find variable c

It is because the previous class hides its objects ( variable c ) by data hiding.

This way a class limits the access of data securing it!

Hope it helps


_____________________________________________________________________


Similar questions