0% found this document useful (0 votes)
3 views2 pages

Java Exp 1

The document provides an overview of classes and objects in Java, explaining their definitions, purposes, and how they contribute to object-oriented programming. It includes a simple Java program example that demonstrates the creation of a Car class and an object of that class. The program outputs the details of the created Car object, showcasing the practical application of classes and objects.

Uploaded by

hitep87172
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)
3 views2 pages

Java Exp 1

The document provides an overview of classes and objects in Java, explaining their definitions, purposes, and how they contribute to object-oriented programming. It includes a simple Java program example that demonstrates the creation of a Car class and an object of that class. The program outputs the details of the created Car object, showcasing the practical application of classes and objects.

Uploaded by

hitep87172
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

Aim: Program on class and objects

Objective: To Understands and implement a simple java program using classes


and objects to learn how java treats data and behaves in an object oriented
manner.

Tools : Eclipse, Notepad++, Java(JPK)

THOERY:

1)What is class in Java?

A class in Java is a template that defines the structure and behavior of objects. It contains variables
(attributes) and methods (functions) to describe what an object is and what it can do.

2)What is object in Java?

In Java, an object is a specific instance of a class created during the program's execution. It holds
actual values in its fields, giving it a unique state. For example, if you create a Dog object with a name
and age, that specific dog has its own identity and behavior. You can then make it perform actions like
barking or running by calling its methods. Objects are stored in memory and are essential to how Java
programs run, allowing code to be organized in a way that mirrors real-world concepts.

3)Why do we use classes and objects in Java?

We use classes and objects in Java to make programs modular, organized, and closer to how things
work in the real world. Eg A class acts like a blueprint—it defines what something is and how it behaves.
For example, you can define a class called Car that describes properties like color and speed, and
actions like driving or braking. Then, using that blueprint, you create objects like myCar or yourCar,
each with their own specific details but based on the same design.

Syntax:

class Car {

String brand;

String model;

int year;

Car(String brand, String model, int year) {

[Link] = brand;
[Link] = model;

[Link] = year;

void displayInfo() {

[Link]("Car: " + brand + " " + model + " (" + year + ")");

public class Main {

public static void main(String[] args) {

Car myCar = new Car("Honda", "Civic", 2021);

[Link]();

Output:

Car: Honda Civic (2021)

You might also like