Java is an object-oriented programming language. Everything in Java is associated with classes and objects, along with its attributes and methods.
A class is a group of objects which have common
properties. It is a template or blueprint from which objects are created. It is
a logical entity. It can't be physical. To create a class, keyword “class”
is used.
A class in Java can contain:
- Fields (data members)
- Methods
- Constructors
- Blocks
- Nested
class and interface
Syntax to declare a class:
class <class_name>{
field;
method;
}
An object in Java is the physical as well as a
logical entity, whereas, a class in Java is a logical entity only. An
entity that has state and behavior is known as an object.
An object has three characteristics:
- State: represents the data (value) of an object.
- Behavior: represents the behavior (functionality) of an object
such as deposit, withdraw, etc.
- Identity: An object identity is typically implemented via a
unique ID. The value of the ID is not visible to the external user.
However, it is used internally by the JVM to identify each object
uniquely.
An object is an instance of a class. A class is
a template or blueprint from which objects are created. So, an object is the
instance(result) of a class.
Syntax to create an object:
classname
object = new classname;
No comments:
Post a Comment