Java Unit 1
Java Unit 1
1. Object:
Any entity that has state and behavior is known as an object.
For example, a chair, pen, table, keyboard, bike, etc. It can be physical or logical.
Example: A dog is an object because it has states like color, name, breed, etc. as well as
behaviors like wagging the tail, barking, eating, etc.
2. Class
Collection of objects is called class. It is a logical entity.
Class is a predefined or user-defined template from which objects are created.
3. Inheritance
When one object acquires all the properties and behaviors of a parent object, it is known
as inheritance. It provides code reusability.
4. Polymorphism
If one task is performed in different ways, it is known as polymorphism.
5. Abstraction
Hiding internal details and showing functionality is known as abstraction.
For example phone call, we don't know the internal processing.
5. Encapsulation
Binding (or wrapping) code and data together into a single unit are known as
encapsulation.
For example, a capsule, it is wrapped with different medicines.
A java class is the example of encapsulation.
Encapsulation is a means of binding data variables and methods together in a class. Only
objects of the class can then be allowed to access these entities. This is known as data
hiding and helps in the insulation of data.
Advantages of OOPS:
Modularity: OOP divides complex systems into smaller components, making the
codebase easier to comprehend, create, and maintain.
Encapsulation: Protects data integrity and privacy by restricting direct access and
allowing controlled access through methods.
Flexibility and Scalability: OOP enables easy addition and modification of features
without impacting the entire codebase.
Code Organization: OOP promotes a structured approach, enhancing collaboration and
code readability.
Code Maintenance: Changes and bug fixes can be made to specific objects or classes
without affecting other parts of the system, reducing errors and improving debugging.
Code Reusability: OOP encourages the development of reusable code elements, saving
time and improving system reliability.
Better Problem Solving: OOP models real-world systems, allowing developers to create
intuitive solutions that closely mimic real-world circumstances.
Applications of OOPs
1. Software Development:
OOPs, are widely used in software development because it allows developers to design
modular and reusable code.
It improves code organization by encapsulating data and methods within objects, making
complex software systems easier to manage and maintain.
OOPs lends itself well to GUI development, giving a natural approach to model and
representing graphical elements. Developers may construct engaging and intuitive user
interfaces using classes and objects.
3. Game Development:
OOPs are commonly used in game development due to their ability to express game
things as objects. Complex interactions between people, objects, and settings are common
in games. Developers can use OOPs to describe these entities as objects and define their
behaviors and characteristics.
4. Database Management Systems:
Encapsulation and abstraction are OOPs ideas used in database management systems
(DBMS). OOPs languages like Python and Java have libraries like JDBC and SQL.
Database activities can be encapsulated within objects, enhancing code organization and
maintainability. OOPs also enables the building of data models, which makes mapping
database tables easier.
OOPs are widely utilized in mobile app development, powering popular platforms such
as Android and iOS. Languages that adhere to OOPs concepts, like Java and Swift,
enable developers to create robust and scalable mobile applications.
6. Web-based Applications
Java is also used to develop web applications. It provides vast support for web
applications through Servlets, Struts, or JSPs. With the help of these technologies, you can
develop any kind of web application that you require.
7. Enterprise Applications
Java is the first choice of many software developers for writing applications and Java
Enterprise Edition (Java EE) is a very popular platform that provides API and runtime
environment for scripting. It also includes network applications and web-services.
8. Distributed Applications:
Distributed applications have several common requirements that arise specifically because
of their distributed nature and of the dynamic nature of the system and platforms they
operate on.
9. Cloud-Based Applications:
Cloud computing means on-demand delivery of IT resources via the internet with pay-as-
you-go pricing.
It provides a solution for IT infrastructure at a low cost. Java provides you with features
that can help you build applications meaning that it can be used in the SaaS, IaaS and
PaaS development. It can serve the companies to build their applications remotely or help
companies share data with others, whatever the requirement.
Limitations of OOP:
1. The length of the programmes developed using OOP language is much larger
than the procedural approach. Since the programme becomes larger in size, it
requires more time to be executed that leads to slower execution of the
programme.
2. Everything is treated as object in OOP so before applying it we need to have
excellent thinking in terms of objects.
3. Software developed using this approach requires a substantial amount of pre-work
and planning.
4. In certain scenarios, these programs can consume a large amount of memory.
Features of Java
1. Simple
Java is a simplified version of the C++ language, and therefore, it is familiar also.
There is no support of pointers, preprocessor header files, operator overloading, and
multiple inheritances in Java. This makes Java easier as compared to C++.
2. Object-oriented
Objects
Classes
Inheritance
Encapsulation / Data hiding
Abstraction
Polymorphism
3. Platform-independent
Java is a platform-independent language as the source code of Java can run on multiple
operating systems. Java programs can run on any machine or the operating system that
does not need any special software installed.
4. Portable
Java is portable because Java code is executable on all the major platforms. Once we
compile Java source code to bytecode, we can use it in any Java-supported platform
without modification
Java is portable because we can carry bytecode over to any other platform it runs on.
Java is a multithreaded language that means it can handle different tasks simultaneously.
Java supports multithreaded programs, in which there is no need to wait for one task to
finish for another to start.
7. Distributed
Java is distributed because it facilitates users to create distributed applications in Java. RMI
and EJB are used for creating distributed applications. This feature of Java makes us able to
access files by calling the methods from any machine on the internet.
What is JDK?
JDK stands for java development kit.
It internally contains JRE & JVM
JDK provides all the tools to work with java languages.
What is JRE?
JRE stands for java runtime environment.
It provides environment to execute the java program.
It provides the class libraries and other resources that a specific Java program requires
to run.
It internally contains JVM which is responsible to execute java program.
The JRE is one of three interrelated components for developing and running Java
programs. The other two components are as follows:
1. Java Development Kit, or JDK
2. Java Virtual Machine, or JVM
The JRE combines Java code created by using the JDK with the necessary
libraries required to run it on a JVM and then creates an instance of the JVM that
runs the resulting program.
How does JRE work?
The Java Runtime Environment (JRE) runs on top of the operating system,
providing additional Java-specific resources. The Java Development Kit (JDK)
and JRE interact to create a sustainable runtime environment that runs Java
program files on any machine. The JRE uses three core components to work.
ClassLoader
The Java ClassLoader dynamically loads all classes necessary to run a Java program.
Bytecode verifier
The bytecode verifier ensures the format and accuracy of Java code before it passes to the
interpreter.
Interpreter
After the bytecode successfully loads, the Java interpreter creates an instance of the JVM
that allows the Java program to be run
Class Loader: Class loader is a subsystem of JVM. It is used to load class files.
Whenever we run the java program, class loader loads it first.
Class method area: It is one of the Data Area in JVM, in which Class data will be
stored. Static Variables, Static Blocks, Static Methods, Instance Methods are stored in
this area.
JIT compiler: The Just-In-Time (JIT) compiler is a part of the runtime environment.
The JIT compiler compiles the bytecode of that method into machine code.
Garbage collector: As the name explains that Garbage Collector means to collect the
unused material.
It tracks each and every object available in the JVM heap space and removes unwanted
ones.
Following diagram that depicts the relationship between all these components.
Java Tokens:
Tokens known as the fundamental building blocks of the program. Tokens can be
classified as follows:
1. Keywords
2. Identifiers
3. Constants
4. Special Symbols
5. Operators
6. Comments
Keyword:
Keywords are pre-defined or reserved words in a programming language. Each keyword
is meant to perform a specific function in a program. Since keywords are referred
names for a compiler, they can’t be used as variable names because by doing so, we are
trying to assign a new meaning to the keyword which is not allowed. Java language
supports the following keywords:
2. Identifiers:
Identifiers are used as the general terminology for naming of variables, functions and
arrays. These are user-defined names consisting of an arbitrarily long sequence of
letters and digits with either a letter or the underscore (_) as a first character. Identifier
names must differ in spelling and case from any keywords. You cannot use keywords as
identifiers
MyVariable
MYVARIABLE
myvariable
x
i
x1
i1
_myvariable
$myvariable
sum_of_array
geeks123
3. Constants/Literals:
Constants are also like normal variables. But the only difference is, their values cannot
be modified by the program once they are defined. Constants refer to fixed values. They
are also called as literals. Constants may belong to any of the data type.
Syntax:
final data_type variable_name;
4. Special Symbols:
The following special symbols are used in Java having some special meaning and thus,
cannot be used for some other purpose.
[] () {}, ; * =
Brackets[]: Opening and closing brackets are used as array element reference. These
indicate single and multidimensional subscripts.
Parentheses(): These special symbols are used to indicate function calls and function
parameters.
Braces{}: These opening and ending curly braces marks the start and end of a block
of code containing more than one executable statement.
comma (, ): It is used to separate more than one statements like for separating
parameters in function calls.
semi colon : It is an operator that essentially invokes something called an
initialization list.
asterick (*): It is used to create pointer variable.
assignment operator: It is used to assign values.
5. Operators:
Java provides many types of operators which can be used according to the need. They
are classified based on the functionality they provide. Some of the types are-
Arithmetic Operators
Unary Operators
Assignment Operator
Relational Operators
Logical Operators
Ternary Operator
Bitwise Operators
Shift Operators
Precedence and Associativity
6. Comments:
In Java, Comments are the part of the program which are ignored by the compiler while
compiling the Program. They are useful as they can be used to describe the operation or
methods in the program. The Comments are classified as follows:
Single Line Comments
Multiline Comments
// This is a Single Line Comment
/*
This is a Multiline Comment
*/
Data types specify the different sizes and values that can be stored in the variable. There
are two types of data types in Java:
1. Primitive data types: The primitive data types include boolean, char, byte, short,
int, long, float and double.
2. Non-primitive data types: The non-primitive data types include Classes, Interfaces,
and Arrays.
Boolean:
The boolean data type has two possible values, either true or false.
Default value: false.
Ex: boolean flag = true;
Byte:
The byte data type can have values from -128 to 127 (8-bit signed two's complement
integer).
It’s used instead of int or other integer data types to save memory if it's certain that the
value of a variable will be within [-128, 127].
Default value: 0
Ex: byte range=124;
Short:
The short data type can have values from -32768 to 32767 (16-bit signed two's complement
integer).
It’s used instead of other integer data types to save memory if it’s certain that the value of the
variable will be within [-32768, 32767].
Default value: 0
short temperature = -200;
Int:
The int data type is a 32-bit signed two's complement integer. Its value-range lies
between - 2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1) (inclusive). Its minimum
value is - 2,147,483,648and maximum value is 2,147,483,647. Its default value is 0.
int a = 100000, int b = -200000;
Long:
The long data type is a 64-bit two's complement integer.
Its value-range lies between -9,223,372,036,854,775,808(-2^63) to
9,223,372,036,854,775,807(2^63 -1)(inclusive).
Its minimum value is - 9,223,372,036,854,775,808and maximum value is
9,223,372,036,854,775,807. Its default value is 0.
The long data type is used when you need a range of values more than those provided by
int.
long a = 100000L, long b = -200000L
float:
Useful for representing real numbers with a fractional part.
Ex: float f1 = 234.5f
double: Used for more precise floating-point calculations.
Ex: double d1 = 12.3
char: The char data type is used to store characters.
Ex: char letterA = 'A'
Structure of java program:
1. Documentation section :
These are optional, but we suggest you use them because they are useful to understand
the operation of the program
/* Multiline comment
in Java */
Package Declaration
You can create a package with any name. A package is a group of classes that are
defined by a name. That is, if you want to declare many classes within one element, then
you can declare it within a package. It is an optional part of the program.
Import statements:
This line indicates that if you want to use a class of another package, then you can do
this by importing it directly into your program.
import [Link].*; //imports all the classes from the java applet package
Interface Section
Class Definition
A class is a collection of variables and methods that operate on the fields. Every program
in Java will have at least one class with the main method.
This is a compulsory part of the structure of Java program. This is the entry point of the
compiler where the execution starts.
The main() method should be defined inside a class. We can call other functions and
create objects using this method.
Operators In java:
Operators in Java are the symbols used for performing specific operations in Java.
1. Arithmetic Operators
2. Unary Operators
3. Assignment Operator
4. Relational Operators
5. Logical Operators
6. Ternary Operator
7. Bitwise Operators
8. Shift Operators
1. Arithmetic Operators
Operators Operations
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
class Main
{
public static void main(String[] args)
{
// declare variables
int a = 15, b = 5;
// addition operator
[Link]("a + b = " + (a + b));
// subtraction operator
[Link]("a - b = " + (a - b));
// multiplication operator
[Link]("a * b = " + (a * b));
// division operator
[Link]("a / b = " + (a / b));
// modulo operator
[Link]("a % b = " + (a % b));
}}
Assignment Operators are mainly used to assign the values to the variable that is situated
in Java programming. There are various assignment operators in Java, such as
Operators Examples Equivalent to
= X = Y; X = Y;
+= X += Y; X = X + Y;
-= X -= Y; X = X - Y;
*= X *= Y; X = X * Y;
/= X /= Y; X = X / Y;
%= X %= Y; X = X % Y;
class Main
{
public static void main(String[] args)
{
// create variables
int a = 5;
int var;
// assign value using =
var = a;
}
}
Java relational operators are assigned to check the relationships between two particular
operators. There are various relational operators in Java, such as
// create variables
int a = 7, b = 11;
// value of a and b
[Link]("a is " + a + " and b is " + b);
// == operator
[Link](a == b); // false
// != operator
[Link](a != b); // true
// > operator
[Link](a > b); // false
// < operator
[Link](a < b); // true
// >= operator
[Link](a >= b); // false
// <= operator
[Link](a <= b); // true
}
}
Logical Operators in Java
Logical Operators in Java are used for checking whether the expression is true or false. It
is generally used for making any decisions in Java programming.
Operators Example Meaning
(true) only if both of the expressions
&& [ logical AND ] expression1 && expression2
are true
|| [ logical OR ] expression1 || expression2 (true) if one of the expressions in true
(true) if the expression is false and
! [ logical NOT ] !expression
vice-versa
class Main
{
public static void main(String[] args)
{
// && operator
[Link]((6 > 3) && (8 > 6)); // true
[Link]((6 > 3) && (8 < 6)); // false
// || operator
[Link]((6 < 3) || (8 > 6)); // true
[Link]((6 > 3) || (8 < 6)); // true
[Link]((6 < 3) || (8 < 6)); // false
// ! operator
[Link](!(6 == 3)); // true
[Link](!(6 > 3)); // false
}
}
Unary Operators
unary operators are the types that need only one operand to perform any operation like
increment, decrement, negation etc.
Operators Operator Name Description
It is used to denote
+ Unary Plus
a positive value.
It is used to denote
- Unary Minus
a negative value.
++ Increment operator Increments value by 1
-- Decrement Operator Decrements value by 1
Reverse the value of boolean
! Logical complement operator
variable
// Increment operator
int count = 5;
// Decrement operator
// NOT operator
Bitwise operations directly manipulate bits. In all computers, numbers are represented
with bits, a series of zeros and ones.
Signed Left << Operand << It moves all the bits of the operand towards the
Shift number left by a given number.
Signed Right >> Operand >> It moves all the bits of the operand towards the
Shift number right by a given number.
Syntax:
Precedence is the priority order of an operator, if there are two or more operators in an
expression then the operator of highest priority will be executed first then higher, and
then high.
Associativity tells the direction of execution of operators that can be either left to
right or right to left.
Typecasting is the process of converting the value of a single data type (such as an
integer [int], float, or double) into another data type.
The compiler performs the automatic conversion, and a programmer does the manual
conversion.
Types of Type Casting in Java
Converting a lower data type into a higher one is called widening type casting. It is also
known as implicit conversion
It is done automatically.
byte -> short -> char -> int -> long -> float -> double
For example, the conversion between numeric data type to char or Boolean is not done
automatically. Also, the char and Boolean data types are not compatible with each other.
Let's see an example.
Converting a higher data type into a lower one is called narrowing type casting. It is also
known as explicit conversion.
It is done manually by the programmer. If we do not perform casting then the compiler
reports a compile-time error.
1. double -> float -> long -> int -> char -> short -> byte
Selection statements are a program control structure in Java. As the name suggests, they are
used to select an execution path if a certain condition is met.
1. The if Statement
Ex:
public class Student {
public static void main(String[] args) {
int x = 20;
if(x > 18) {
[Link]("Eligible for vote");
}
}
}
2) if-else statement
The if-else statement is an extension to the if-statement, which uses another block of
code, i.e., else block. The else block is executed if the condition of the if-block is
evaluated as false.
[Link] If-else:
if (condition1) {
/* code to be executed if condition1 is true */
if (condition2) {
/* code to be executed if condition2 is true */
} else {
/* code to be executed if condition2 is false */
}
} else {
/* code to be executed if condition1 is false */
}
Example:
class NestedIfDemo
{
public static void main(String args[])
{
int i = 10;
if (i == 10)
{
// First if statement
if (i < 15)
[Link]("i is smaller than 15");
// Nested - if statement
// Will only be executed if statement above
// it is true
if (i < 12)
[Link]("i is smaller than 12 too");
else
[Link]("i is greater than 15");
}
}
}
The if-else-if statement contains the if-statement followed by multiple else-if statements.
Syntax:
if(condition_expression_One) {
statement1;
} else if (condition_expression_Two) {
statement2;
} else if (condition_expression_Three) {
statement3;
} else {
statement4;
}
Example:
class GFG {
public static void main(String[] args)
{
// initializing expression
int i = 20;
// condition 1
if (i == 10)
[Link]("i is 10\n");
// condition 2
else if (i == 15)
[Link]("i is 15\n");
// condition 3
else if (i == 20)
[Link]("i is 20\n");
else
[Link]("i is not present\n");
[Link]("Outside if-else-if");
}
}
[Link] Statements
The switch statement in Java is a multi-way branch statement.
The Java switch statement executes one statement from multiple conditions.
Syntax:
switch(expression)
{
case value1 :
// Statements
break; // break is optional
case value2 :
// Statements
break; // break is optional
....
....
....
default :
// default Statement
}
Example:
public class GFG {
// Case
case 1:
dayString = "Monday";
break;
// Case
case 2:
dayString = "Tuesday";
break;
// Case
case 3:
dayString = "Wednesday";
break;
// Case
case 4:
dayString = "Thursday";
break;
// Case
case 5:
dayString = "Friday";
break;
// Case
case 6:
dayString = "Saturday";
break;
// Case
case 7:
dayString = "Sunday";
break;
// Default case
default:
dayString = "Invalid day";
}
[Link](dayString);
}
}
Looping structures:
1. For Loop
2. While loop
3. Do-while loop
1. For Loop:
for loop is used to iterate a part of the program several times. If the
number of iteration is fixed, it is recommended to use for loop.
Syntax:
for(initialization; condition; increment/decrement){
//statement or code to be executed
}
Example:
Syntax:
for (type var : array)
{
statements using var;
}
Example:
class Easy
// array declaration
3. While loop:
while loop is used to iterate a part of the program repeatedly until the specified
condition is true.
As soon as the condition becomes false, the loop automatically stops.
Syntax:
while (condition){
//code to be executed
Increament / decrement statement
}
4. Do while loop:
Java do-while loop is used to iterate a part of the program repeatedly, until the specified
condition is true.
If the number of iteration is not fixed and you must have to execute the loop at least once,
it is recommended to use a do-while loop.
SYNTAX:
do{
//code to be executed / loop body
//update statement
}while (condition);
5. Nested Loops:
A Nested loop means a loop statement inside another loop statement.
Syntax:
Nested For loop
for ( initialization; condition; increment ) {
for ( initialization; condition; increment ) {
// statement of inside loop
}
// statement of outer loop
}
Syntax:
while(condition) {
while(condition) {
// statement of inside loop
}
Break Statements:
The Java break statement is used to break loop or switch statement. It breaks the current flow of
the program at specified condition.
We can use Java break statement in all types of loops such as for loop, while loop and do-while
loop.
Syntax:
jump-statement;
break;
Example:
public class BreakExample {
public static void main(String[] args) {
//using for loop
for(int i=1;i<=10;i++){
if(i==5){
//breaking the loop
break;
}
[Link](i);
}
}
}
Continue Statement
The Java continue statement is used to continue the loop. It continues the current flow of the
program and skips the remaining code at the specified condition.
We can use Java continue statement in all types of loops such as for loop, while loop and do-
while loop.
Syntax:
Statement;
Continue;
Labeled Loop:
A label is a valid variable name that denotes the name of the loop to where the control of
execution should jump. To label a loop, place the label before the loop with a colon at the
end. Therefore, a loop with the label is called a labeled loop
Syntax:
labelname:
for(initialization; condition; incr/decr)
{
//functionality of the loop
}
public class LabeledForLoop
{
public static void main(String args[])
{
int i, j;
for(i=1;i<=5;i++)
{
[Link]();
//inner loop
inner: //label
for(j=1;j<=10;j++)
{
[Link](j + " ");
if(j==9)
break inner;
}
}
}
}
Array in Java:
An array is a data structure that stores elements of the same type.
You can put some data in each cell (one data element per cell). A specific cell is accessed
using its number. An element's number in the array is also called an index.
An array is homogeneous, i.e. all its cells contain elements of the same type.
1. Declaring an array:
i. dataType[] arrayName;
Ex: int[] myArray;
ii. dataType arrayName[];
Ex: int myArray[];
2. Initialization an Array in Java
datatype[] arrayName = new datatype[length]; OR
datatype arrayName[] = new datatype[length];
Array will be -
10 0 37 0 0
2. Initialize while declaring - We can also initialize the whole array while declaring it
just by using curly brackets {}. The string must be in quotes, whereas int, float,
etc., do not require that.
int[] myArray = {1, 2, 3, 4, 5}; // For integer type
String[] myArray1 = {"A", "B", "C", "D"}; // For string type
Ex: class ArrayDemo {
public static void main(String[] args) {
// declares an array of integers
int[] anArray;
// Creating a 2D array
ArrayName = new DataType[r][c];
Ex: /Declaring 2D array
int[][] a;
//Creating a 2D array
a = new int[3][3];
import [Link];
2. class MultiDimArrayDemo {
public static void main(String[] args) {
String[][] names = {
{"Mr. ", "Mrs. ", "Ms. "},
{"Smith", "Jones"}
};
// Mr. Smith
[Link](names[0][0] + names[1][0]);
// Ms. Jones
[Link](names[0][2] + names[1][1]);
}
}
Array Manipulation:
Common Array Manipulation Operations:
Declaration and Initialization: Creating an array and optionally assigning initial
values.
Accessing Elements: Retrieving values at specific indices.
Modifying Elements: Changing the value of an element at a given index.
Iterating through Elements: Looping through the array to process each element.
Finding Array Length: Determining the number of elements in the array.
Copying Arrays: Creating a new array with the same elements as an existing one.
Sorting Arrays: Arranging elements in ascending or descending order.
Searching Arrays: Finding specific elements within the array.
Example:
class Car {
String color;
void drive() {
[Link]("Car is driving");
}
}
[Link]();
2. Encapsulation
Example:
class BankAccount
balance += amount;
return balance;
}}
3. Inheritance
Example:
class Animal {
void eat()
{ [Link]("Eating...");
4. Polymorphism
Ability of an object to take many forms.
Two types:
Example:
class Shape {
void draw()
{ [Link]("Drawing shape"); }
5. Abstraction
Example:
}
class Bike extends Vehicle
void move()
}}
Constructors :
A constructor in Java is a special member that is called when an object is created. It
initializes the new object’s state.
Rules for Writing Constructors in Java
The name of the constructor must be the same as the name of its class.
A constructor must have no return type. It can not have not even void as its
return type.
We can use the access modifiers with a constructor to control its access so
that other classes can call the constructor.
Types of Constructores
1. Default Constructor
2. Parameterised Constructor
3. Copy constructor
1. Default Constructor
class Myclass
int number;
String name;
Myclass ()
[Link]([Link]);
[Link]([Link]);
}
public class Car {
String model;
int year;
// Parameterized Constructor
public Car(String model, int year) {
[Link] = model;
[Link] = year;
}
Method Overloading:
Method Overloading is a feature that allows a class to have multiple methods with the
same name but with different number, sequence or type of parameters. In short multiple
methods with same name but with different signatures. For example the signature of
method add(int a, int b) having two int parameters is different from signature of
method add(int a, int b, int c) having three int parameters.
Three ways to overload a method
1. Number of parameters.
For example: This is a valid case of overloading
add(int, int)
add(int, int, int)
2. Data type of parameters.
For example:
add(int, int)
add(int, float)
3. Sequence of Data type of parameters.
For example:
add(int, float)
add(float, int)
Example:
class DisplayOverloading
{
//adding two integer numbers
int add(int a, int b)
{
int sum = a+b;
return sum;
}
//adding three integer numbers
int add(int a, int b, int c)
{
int sum = a+b+c;
return sum;
}
}
class JavaExample
{
public static void main(String args[])
{
DisplayOverloading obj = new DisplayOverloading();
[Link]([Link](10, 20));
[Link]([Link](10, 20, 30));
}
}
Output:
30
60