A class is a blueprint or template or prototype using which you can create any number of individual objects, you can consider that class is a logical entity, and the class contains fields and methods, the definition of class is shown below
// instance variable 1
modifier datatype field1;
// instance variable 2
modifier datatype field2;
modifier datatype method1()
if you see the above code the instance variables provides state of the class or object and the method defines the behavior of the object or class
What is an Object?
An object represents a physical entity, the objects are an instance of a class and every instance will have its own behavior and state, the state represents instance variable and behavior represents methods, you can create any number of object’s for the above button code
You can create an object of Button class by using below code, here I am creating three objects which are button1, button2 and button3
The new keyword will create an object in the heap memory, the address of the object will be stored in the stack memory and also the values of the primitive types will be stored in the stack memory
The class contains instance variables, methods, constructor’s, for more information on variables and constructors refer below-mentioned articles, here I am going to explain methods
The method is a behavior of a class and if you want to execute set of statements to solver particular business problem then you can use methods, you can have more than one method within a class ,generally the methods which are in the class are always unique but, if you want to have the same name for more than one method then you must use method overloading,
A technology enthusiast and a professional blogger from India. Through out my IT career, I have had the pleasure of working on various new technologies and built products like www.ziprides.com and some other products. Unfortunately, my attempts have not given me the desired results and as a result, I have finally decided to build a professional blog where I would like to share all my learnings and hoping to learn from other enthusiasts around the world.