Module 2
Module 2
CLASS in java
Class
A class is a user-defined data type. It consists of data members and
member functions, which can be accessed and used by creating an
object of that class
A class is like a blueprint for an object.
Object
It is a basic unit of Object-Oriented Programming and represents
the real-life entities. An Object is an instance of a Class.
When a class is defined, no memory is allocated but when it is
instantiated (i.e. an object is created) memory is allocated. An object
has an identity, state, and behavior. Each object contains data and
code to manipulate the data.
Objects can interact without having to know details of each other’s
data or code, it is sufficient to know the type of message accepted
and type of response returned by the objects.
For example “Dog” is a real-life Object, which has some
characteristics like color, Breed, Bark, Sleep, and Eats.
Object creating for the class Dog
Dog d =new Dog ();
Simple OOP Program to define class and object concept
OOP example program with scanner class
OUTPUT
Initialize objects through a constructor
Example
Initialize objects through a constructor_Example