Tuesday, 8 October 2019

Object


Introduction to object 

java,object,java tutorial,object in java,object class in java,what is object in java,class and object in java,class in java,java objects,java (programming language),java classes,java tutorials,classes in java,object oriented programming java,


What are object-
Objects are a unique entity which contain data and function group together.

In Object oriented programming problem is break down to small components called object's.

Understanding objects-
To understand objects in object oriented programming(OOP) let's consider a object from real world.

The object from real world consist following characters-
• It is visible .
• It can be defined and describe.
• It can be brought into action.

Example let's consider camera as a real world object. It has -
• Camera is visible
• Camera are used to click photographs
• We can click photos by clicking a button on camera.
Every object contains a characteristic and behavior let take example of potato

It's characteristic-
• It is brown in colour
• It is oval in shape
It's behavior-
• It is used to make vegetables
• It is also used in making many products like chips.

The objects, which we have discussed above are real world objects

 In fact, a program does not deal with real world object. The program uses software objects.

 Let us relate a real world object with the software object.

• The state or characteristic of real world object are data members in software object.
• In the same way behavior in real world object are considered as the function or method in software object.

You can understand by given below image
java,object,java tutorial,object in java,object class in java,what is object in java,class and object in java,class in java,java objects,java (programming language),java classes,java tutorials,classes in java,object oriented programming java,
Let's consider a class has object car. So by above picture you can understand the characteristics of object(car) are fuel and maxspeed, and its behavior are drive(),refule(),getfule(),setspeed(),etc.

Creation of object in a program-

1) Using new Keyword : Using new keyword is the most basic way to create an object.

 This is the most common way to create an object in java. Almost 99% of objects are created in this way.

 By using this method we can call any constructor we want to call (no argument or parameterized constructors).


2) Using New Instance: 

If we know the name of the class & if it has a public default constructor we can create an object –Class.forName

We can use it to create the Object of a Class. Class.forName actually loads the Class in Java but doesn’t create any Object. 

To Create an Object of the Class you have to use the new Instance Method of the Class.


3) Using clone() method: 
Whenever clone() is called on any object, the JVM actually creates a new object and copies all content of the previous object into it.
 Creating an object using the clone method does not invoke any constructor.
To use clone() method on an object we need to implement Cloneable and define the clone() method in it.

No comments:

Post a Comment