Can you explain the relation between class and object? Explain with an example

1. 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

}

}

Comments

Popular posts from this blog

Bluetooth Data Transfer Example

How to Create & Extract tar.gz and tar.bz2 Files in Linux