• Register
499 points
8 4 3

Difference between class and method in java

The main difference between Class and Method is that class is a blueprint or a template to create objects while method is a function that describes the behavior of an object.

A programming paradigm is a style that explains the way of organizing the elements of a program. Object Oriented programming (OOP) is a common software development paradigm. The developers can model the software into a set of objects and these objects communicate with each other by passing messages. Class and method are two concepts related to OOP. Moreover, a method is written inside a class.

Classes act as a blueprint or a template.

In a blueprint/template class, you write code that will createyour variables and methods - the class is defined by its properties (variable fields) and its behaviours (the methods). And an object is then created out of this class.

As stated above a method is found inside a class. Methods define the operations that can be performed in the program. To put it simply, it is code that can be called whenever the specific task needs to be performed.

Here is an example of a blueprint class with methods and fields:

 
public class Cube { 
 
	/*FIELDS - properties of the blueprint class*/ 
	int length; 
	int breadth; 
	int height; 
 
	/*METHOD - describes the behaviour of the the blueprint class 
	  When the getVolume() method is called, it returns the volume of  
	  the cube that is calculated from the fields. 
	*/ 
	public int getVolume() { 
		return (length * breadth * height); 
	} 
}

    More Posts

    Difference between class and id attribute in html Sanjana Sagar - May 28
    What is the difference between id and class in css Sanjana Sagar - May 22
    Difference between static and dynamic in java Sanjana Sagar - May 29
    Difference between abstract and interface in java Sanjana Sagar - May 28
    Difference between abstract and interface in java Sanjana Sagar - May 28
    What is the difference between java and core java Sanjana Sagar - May 28
    Difference between nested class and inner class in java Sanjana Sagar - May 19
    What is the difference between abstraction and encapsulation in java Sanjana Sagar - May 20
    What is the difference between a class and an interface mhfaisal - Jun 12
    Difference between inner class and nested class Sanjana Sagar - May 29