0% found this document useful (0 votes)
12 views

Experiment 3

Uploaded by

sheetdbtest2202
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Experiment 3

Uploaded by

sheetdbtest2202
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Anish Dharnidhar AI & DS Batch S23 Roll no : 129

Aim: Programs on Classes and Objects (Learning Outcome 2)


Theory

In Java, a class is a fundamental building block that serves as a blueprint for creating objects.
It encapsulates data for the object, known as attributes or fields, and defines the behaviour of
the object through methods or functions. For example, a Car class might include fields for the
car's colour, model, and year, as well as methods to perform actions like driving. The class
also typically includes a constructor, a special method used to initialise new objects. An object,
then, is an instance of a class; it is created based on the class template and has its own
unique set of data that adheres to the structure defined by the class. This allows for the
creation of multiple objects from a single class, each with its own specific data but sharing the
same methods and behaviours. In this way, classes and objects enable the principles of
object-oriented programming, such as encapsulation, inheritance, and polymorphism,
facilitating code reuse and modularity.

Difference between a class and an object

Class Object

A blueprint or template for creating An instance of a class, created using


objects. the class blueprint.

Defined once and used to create Created based on the class


objects. definition, multiple objects can be
created.

Defines the properties and Represents a specific example of a


behaviors that objects will have. class with actual data.

Allocated when the class is loaded Allocated when a new object is


(for static members). created (using the new keyword).

Changing the class definition Changes to an object affect only that


changes the blueprint for all future specific instance.
objects.
Anish Dharnidhar AI & DS Batch S23 Roll no : 129

1. Program in Java to calculate a maximum of 4 digits using the concept of class


and object.
Anish Dharnidhar AI & DS Batch S23 Roll no : 129

Output:

2. Program in Java to print the details of student using the concept of class and
object.
Code:
Anish Dharnidhar AI & DS Batch S23 Roll no : 129

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy