what is the realationship between class and object? illustrate with a exmple.
Answers
Answer:
A class defines the properties and behavior for the objects represented by the abstraction. Abstraction is a property of object oriented programming. It denotes the essential properties and behaviors of an object. It hides code and data. A class thus denotes a category of objects and act as a blueprint for creating such objects. An object exhibits the property and behaviors defined by its class. Generally, an object is an instance of a class.
For example:
// program for adding two numbers
class sum //declaration of a class
{
int a=10; //declaration of variables
int b=20;
int c;
public void add()// defining a function
{
c=a+b;
System.out.println("The sum is="+c);
}
public static void main(String args[])// main function
{
sum s= new sum();// making a object of class sum
s.add();
//accessing the function with the help of object
}
}
Answer:
AN OBJECT IS AN ELEMENT OR A PARR OF A CLASS....
CLASS HOLDS OR CONTAINS...THE OBJECT
WITHIN ITSELF....
Explanation:
EG...A CAR COMPANY IS AN CLASS...WHEREAS THE DIFFERENT MODEL OF THE CARS ARE KNOWN AS ITS OBJECTS.....