0% found this document useful (0 votes)
51 views7 pages

Oop Report

The document discusses objects in Java programming. It defines that objects are created using classes in Java, and provides the syntax for creating an object which involves declaring a class name and using the new keyword. It describes characteristics of objects such as having a unique identity and type. Objects contain state defined by attributes and behavior defined by methods. Methods represent specific actions or processes that can be performed on an object. The document provides examples of creating Lamp objects and calling their turnOn() and turnOff() methods.

Uploaded by

kaka shi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views7 pages

Oop Report

The document discusses objects in Java programming. It defines that objects are created using classes in Java, and provides the syntax for creating an object which involves declaring a class name and using the new keyword. It describes characteristics of objects such as having a unique identity and type. Objects contain state defined by attributes and behavior defined by methods. Methods represent specific actions or processes that can be performed on an object. The document provides examples of creating Lamp objects and calling their turnOn() and turnOff() methods.

Uploaded by

kaka shi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Preoared by : Ahmad Taha Aziz.

University of garmian.
Stage 2
IT department.
Supervisor: MR.salar.
Report about: objects in java.
Object in Java
Java is a powerful object-oriented programming language that consists
of objects and classes. The objects make it easier to map the real-life
entities while coding. The objects will be used all the time while
programming in java. The objects in java are easy to define and use. It is
necessary to understand Classes and Objects because everything in an
object-oriented programming language like Java is based upon them.

How to Create an Object in Java?


 If you are familiar with Java programming, you may know that an object

is created using a class in java. The class is nothing, but it provides a

blueprint for creating an object. The class is used to instantiate an object.

So technically, we will be having the class declared already before we

create the object in Java.

 Let’s see the syntax of creating an object

 Syntax:

ClassName objectName = new ClassName();



 We can also declare an object in a different way. First, we will declare it,

and then we can initialize it.

ClassName objectName;
Name = new ClassName();

Characteristics of Object in Java


 Every object in java will have its own identity. No two objects will have

the same identity. Every object will correspond to a different memory

location, and the address of the memory location will not be available to

the user.

 An object will have its type associated with it. Every object will have a

data type as a class.

 An object will also have two things state and behavior declared in it.

These things are declared in class itself. The state will define attributes,

and behavior will define the actions related to the class.

Methods of Object in Java


 The second main thing which we declare while creating a class is

methods. These methods are nothing but are like the functions which
are declared in a class. The methods are again specific to the class in

which they are declared. The methods represent a specific action or

process to be performed when called using the object reference. The

methods are like behavior in the real world. For example, the mobile will

perform the action of calling or dialing. Calling action is nothing but the

behavior of the mobile.

 While programming in Java, we will normally create an object and assign

values to its data members and perform specific actions related to ii

using the methods. The methods are an easy way to combine and

perform the specific actions which are required while programming.

 We can perform anything which is the requirement in methods. The

methods can also access the data members defined in the class. we can

perform the actions on the data members in a class. We can define any

number of methods in the class as long as required.


Rules for Object in Java
 There are no such hard rules for the declaration of any object, but we

should follow the standard java naming convention while declaring the

object name.

 We can access the methods of a class only by object reference or by

class reference in special cases, but in any of both situations, we cannot

access or modify the implementation of methods.

 We can reuse the once-defined object as many times as we want.

 We can easily remove or replace the object being used depending upon

the requirement.

 // method to turn on the light


 void turnOn() {
 isOn = true;
 System.out.println("Light on? " + isOn);

 }

 // method to turnoff the light
 void turnOff() {
 isOn = false;
 System.out.println("Light on? " + isOn);
 }
 }

 class Main {
 public static void main(String[] args) {

 // create objects led and halogen
 Lamp led = new Lamp();
 Lamp halogen = new Lamp();

 // turn on the light by
 // calling method turnOn()
 led.turnOn();

 // turn off the light by
 // calling method turnOff()
 halogen.turnOff() }}

Reference:

By: Priya Pedamkar

Uploaded at : Educba website

You might also like