0% found this document useful (0 votes)
8 views3 pages

JPL Expt-3 Minor

sjjabdjdhs

Uploaded by

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

JPL Expt-3 Minor

sjjabdjdhs

Uploaded by

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

Subject: Java Lab Class: SE-IT

Semester: III A.Y. 2024-2025


Experiment No. 3
Aim: Write a program that would print the information (name, year of joining, salary, address) of three
employees by creating a class named 'Employee'

Objectives: To learn how to create an object of class and how one single object can access mnultiple
methods of class in java language.

Prerequisites: It is required that students should know the basic structure of java program along with
how output can be display in organized ways.

Software used: jdk 1.6.0


Problem Statement: Write a program that would print the information (name, year of joining, salary,
address) of three employees by creating a class named 'Employee'. The output should be as follows:

Theory :
Java class :

✔ A class can be defined as a template/blueprint that describes the behavior/state that the
object of its type support.
✔ Following is a sample of a class.Output :
A class can contain any of the following variable types.

✔ Local variables − Variables defined inside methods, constructors or blocks are called local
variables. The variable will be declared and initialized within the method and the
variable will be destroyed when the method has completed.

✔ Instance variables − Instance variables are variables within a class but outside any method.
These variables are initialized when the class is instantiated. Instance variables can be
accessed from inside any method, constructor or blocks of that particular
class.

✔ Class variables − Class variables are variables declared within a class, outside any method, with
the static keyword.

A class can have any number of methods to access the value of various kinds of
methods. In theabove example, barking(), hungry() and sleeping() are methods.

Objects in Java :

✔ Objects have states and behaviors. Example: A dog has states - color, name, breed as well as
behaviors – wagging the tail, barking, eating. An object is an instance of a class.

✔ If we consider the real-world, we can find many objects around us, cars, dogs, humans, etc. All
these objects have a state and a behavior.
If we consider a dog, then its state is - name, breed, color, and the behavior is - barking,
wagging the tail, running.
✔ If you compare the software object with a real-world object, they have very similar charac-
teristics.
✔ Software objects also have a state and a behavior. A software object's state is stored in fields and
behavior is shown via methods.
✔ So in software development, methods operate on the internal state of an object and the ob-
ject-to-object communication is done via methods.
Creating an Object :

✔ As mentioned previously, a class provides the blueprints for objects. So basically, an object is
created from a class. In Java, the new keyword is used to create new objects.
✔ There are three steps when creating an object from a class −
• Declaration − A variable declaration with a variable name with an object type.
• Instantiation − The 'new' keyword is used to create the object.
• Initialization − The 'new' keyword is followed by a call to a constructor. This call
initializes the new object.
✔ Example

✔ If we compile and run the above program, then it will produce the following result –

Output

Passed Name is: tommy

✔ Conclusion :

• Summarize what you understood from this lab.

Prof. Rujata Chaudhari


Prof. Urjashree Patil Dr. Kiran Deshpande
Subject In-charge Head of Department

You might also like