Oop Lab Manual
Oop Lab Manual
UNIVERSITY LYARI
OOP LAB MANUAL
ROLL NO : 43
OUTPUT :
EXAMPLE NO 2:
To print the name:
OUTPUT :
EXAMPLE NO 3 :
Taking input from user
OUTPUT :
EXAMPLE NO 4 :
To replacement of character.
OUTPUT :
EXAMPLE NO 5 :
To find the largest number and also taking the inputs of numbers.
OUTPUT :
EXAMPLE N0 6 :
To find the smallest number and also taking the inputs of numbers.
OUTPUT :
EXAMPLE NO 7 :
Type casting example.
OUTPUT :
EXAMPLE N0 8 :
ASCII code.
OUTPUT :
EXAMPLE NO 9:
Substring is used for select or print the small part or specific part of your
data.
OUTPUT :
EXAMPLE NO 10 :
To length of variable.
OUTPUT :
EXAMPLE NO 11 :
OUTPUT :
EXAMPLE NO 12 :
OUTPUT :
CONSTRUCTOR :
1. Default Constructor.
2. Parameterized constructor.
DePfault Constructor :
A default constructor in Java is created by the compiler itself when the
programmer doesn't create any constructor. The purpose of the
default constructor is to initialize the attributes of the object with their
default values.
EXAMPLE CODE :
OUTPUT :
Parameterized Constructor :
The constructor is said to be a parameterized constructor if the object
contains a number of parameters or arguments. The arguments must
be passed by the user explicitly. For example, If we wish to set our
own values in the class's object fields, we should use a parameterized
constructor.
EXAMPLE CODE :
OUTPUT :
PILLARS IN OOP
OR
BASIC BUILDING BLOCK IN OOP
1. Inheritance.
2. Abstraction.
3. Polymorphism.
4. Encapsulation.
INHERITANCE:
Java Inheritance: In the Java language, classes can be derived from other
classes, thereby inheriting fields and methods from those classes.
Definitions: A class that is derived from another class is called a subclass (also a
derived class, extended class, or child class). The class from which the subclass
is derived is called a superclass (also a base class or a parent class).
Excepting Object, which has no superclass, every class has one and only one
direct superclass (single inheritance). In the absence of any other explicit
superclass, every class is implicitly a subclass of Object.
EXAMPLE:
OUTPUT :
ABSTRACTION:
All programming languages provide abstractions. It can be argued that the
complexity of the problems you’re able to solve is directly related to the kind and
quality of abstraction. An essential element of object-oriented programming is an
abstraction.
EXAMPLE:
OUTPUT :
POLYMORPHISM :
In Core, Java Polymorphism is one of easy concept to understand.
Polymorphism definition is that Poly means many and morphos means forms. It
describes the feature of languages that allows the same word or symbol to be
interpreted correctly in different situations based on the context. There are two
types of Polymorphism available in Java. For example, in English, the verb “run”
means different things if you use it with “a footrace,” a “business,” or “a
computer.” You understand the meaning of “run” based on the other words used
with it.
EXAMPLE:
here is a simple diagram illustrating polymorphism implementation:
EXAMPLE:
OUTPUT:
ENCAPSULATION:
An object's encapsulation allows it to hide its data and methods. It is one of the
fundamental principles of object-oriented programming. Java classes
encapsulate the fields and methods that define an object's state and actions.
Encapsulation enables you to write reusable programs. It also enables you to
restrict access only to public features of an object. Other fields and methods are
private and can be used internally.
EXAMPLE :
OUTPUT :
“THANK
YOU”