A class denotes a category of objects, and acts as a blueprint for creating such objects.
A class models an abstraction by defining the properties and behaviors for the objects representing the abstraction.
An object exhibits the properties and behaviors defined by its class.
The properties of an object of a class are also called attributes, and are defined by fields in Java.
A field in a class definition is a variable which can store a value that represents a particular property.
The behaviors of an object of a class are also known as operations, and are defined using methods in Java. Fields and methods in a class definition are collectively called members.
/* Name of the class has to be "Main" only if the class is public. */
class JavaDemo
{
private String property1;
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
}
}
The process of creating objects from a class is called instantiation. An object is an instance of a class. Creating an object for class JavaDemo
JavaDemo demo = new JavaDemo();
"demo" is an object of class JavaDemo
The new operator returns a reference to a new instance of the JavaDemo class. This reference can be assigned to a reference variable of the appropriate class.
No comments:
Post a Comment