Module-01 Object Oriented Programming using Java – BCS306A
An Overview of Java: Object-Oriented Programming (Two Paradigms, Abstraction, The Three OOP
Principles), Using Blocks of Code, Lexical Issues (Whitespace, Identifiers, Literals, Comments,
Separators, The Java Keywords).
Data Types, Variables, and Arrays: The Primitive Types (Integers, Floating-Point Types, Characters,
Booleans), Variables, Type Conversion and Casting, Automatic Type Promotion in Expressions,
Arrays, Introducing Type Inference with Local Variables.
Operators: Arithmetic Operators, Relational Operators, Boolean Logical Operators, The Assignment
Operator, The ? Operator, Operator Precedence, Using Parentheses.
Control Statements: Java’s Selection Statements (if, The Traditional switch), Iteration Statements
(while, do-while, for, The For-Each Version of the for Loop, Local Variable Type Inference in a for Loop,
Nested Loops), Jump Statements (Using break, Using continue, return).
Java is a high-level, class-based, object-oriented programming language designed to have as few
implementation dependencies as possible. It is widely used for building cross-platform
applications, from mobile apps to enterprise-level systems.
KEY FEATURES OF JAVA
• Platform Independence: Java is a "write once, run anywhere" (WORA) language. Java
programs are compiled into bytecode, which can run on any machine with a Java Virtual
Machine (JVM), regardless of the underlying operating system.
• Object-Oriented: Java is based on the principles of OOP (Object-Oriented Programming).
Key OOP concepts include:
o Encapsulation: Bundling data (attributes) and methods (functions) that operate
on the data into a single unit (class).
o Inheritance: A mechanism that allows one class to inherit properties and
behaviours from another.
o Polymorphism: The ability to process objects differently based on their data type
or class.
o Abstraction: Hiding the implementation details and showing only the essential
features of the object.
• Simple: Java has a clean syntax that is easy to understand, which makes it accessible for
beginners.
• Secure: Java has built-in security features such as bytecode verification, exception
handling, and garbage collection that make it less prone to common security risks.
• Robust: Java emphasizes early checking for possible errors, with features like strong
memory management and exception handling, reducing the likelihood of crashes.
• Multithreading: Java supports multithreading, allowing developers to write programs
that can perform several tasks simultaneously.
• High Performance: Though Java is not as fast as natively compiled languages like C or
C++, its performance is optimized through the use of Just-In-Time (JIT) compilation.
JAVA ARCHITECTURE
Components of Java Architecture
• Java Virtual Machine (JVM): The JVM is an abstract machine that enables a computer to
run Java programs. It converts Java bytecode into machine-specific instructions. JVMs are
available for many hardware and software platforms.
Department of Computer Science & Design, ATMECE, MYSURU 1
Module-01 Object Oriented Programming using Java – BCS306A
• Java Development Kit (JDK): A software development environment used for developing
Java applications and applets. The JDK includes the Java Runtime Environment (JRE), an
interpreter/loader, and other development tools.
• Java Runtime Environment (JRE): A package of software that provides the Java class
libraries, JVM, and other components required to run Java applications.
Fig 01: Components of Java Architecture
There are two processes in Java — Compilation and Interpretation.
• The Java source code goes to the compiler.
• The Java Compiler converts it into byte codes
• The bytes codes are then converted into machine by the JVM
• The Machine code is executed directly by the machine (Operating System)
Fig 02: Main Processes involved in Java Program Execution
TWO PARADIGMS
In programming, paradigms refer to distinct styles or approaches to solving problems and
organizing code. Here are two widely recognized paradigms:
1. Procedural Programming Paradigm
Definition: A programming paradigm that follows a step-by-step approach where a program
is divided into a set of procedures or functions. These functions operate on data, perform
operations, and produce results. The main focus is on the sequence of actions to be executed.
Department of Computer Science & Design, ATMECE, MYSURU 2
Module-01 Object Oriented Programming using Java – BCS306A
Key Concepts:
• Procedures/Functions: Blocks of code that perform a specific task.
• Sequence of Instructions: The program executes in a top-down manner, from one
instruction to the next.
• Variables: Data is stored in variables, and the functions manipulate them.
• Modularity: A program is structured into smaller modules (functions), making it
easier to maintain.
Languages: C, Fortran, Pascal, Basic.
2. Object-Oriented Programming (OOP) Paradigm
Definition: A programming paradigm that is based on the concept of "objects." Objects are
instances of classes that combine both data (attributes) and methods (functions) to
manipulate that data. OOP emphasizes modularity, code reuse, and abstraction.
Key Concepts:
• Class: A blueprint for creating objects, defining attributes and methods.
• Object: An instance of a class with specific values for its attributes.
• Encapsulation: Bundling data and methods together and restricting access to them.
• Inheritance: The ability of a new class to inherit properties and methods from an
existing class.
• Polymorphism: The ability of different classes to respond to the same method call in
different ways.
• Abstraction: Hiding the complex implementation details and showing only the
essential features.
Languages: Java, C++, Python, Ruby.
THE THREE CORE PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING (OOP)
Object-Oriented Programming (OOP) is a programming paradigm that focuses on designing
software using objects and classes. The three main principles of OOP—Encapsulation,
Inheritance, and Polymorphism—play a fundamental role in designing modular, reusable, and
maintainable code.
Encapsulation
Encapsulation is the concept of bundling data (attributes) and methods (functions) that operate
on that data into a single unit, known as a class. It also restricts direct access to some of an object’s
components, which is known as data hiding. This ensures that the internal details of an object
are hidden from the outside world, and access is controlled through public methods (getters and
setters).
Benefits:
• Data protection: Prevents accidental modification of data.
• Code maintainability: Changes to the internal implementation do not affect external
code that uses the class.
Department of Computer Science & Design, ATMECE, MYSURU 3
Module-01 Object Oriented Programming using Java – BCS306A
Example:
class Student {
private String name; // private field
// Getter method to access the private field
public String getName() {
return name;
}
// Setter method to modify the private field
public void setName(String name) {
[Link] = name;
}
}
Inheritance
Inheritance is the principle by which one class (the subclass or derived class) acquires the
properties and behaviours (fields and methods) of another class (the superclass or base class). It
allows code reusability and the extension of existing functionality without modifying the original
class.
Key Points:
Superclass: The parent class whose attributes and methods are inherited.
•
Subclass: The child class that inherits from the superclass.
•
Single and multiple inheritance: Java supports single inheritance (a class inherits from
•
one parent class), but multiple inheritance is achieved using interfaces.
Benefits:
Code reusability: Allows common code to be written once in the superclass and reused
•
by subclasses.
• Extensibility: Subclasses can extend or modify the behavior of the superclass without
altering its original code.
Example
class Vehicle // Superclass
{
int speed;
void displaySpeed() {
[Link]("Speed: " + speed);
}
}
class Car extends Vehicle// Subclass
{
String model;
}
public class Main {
public static void main(String[] args) {
Car myCar = new Car();
[Link] = 100;
[Link] = "Tesla";
[Link](); // Accessing inherited method
}
}
Department of Computer Science & Design, ATMECE, MYSURU 4
Module-01 Object Oriented Programming using Java – BCS306A
Polymorphism
Definition: Polymorphism allows one interface to be used for different types of objects. It enables
a method to do different things based on the object it is acting upon, even though the method call
remains the same. Polymorphism can be compile-time (method overloading) or runtime
(method overriding).
Key Points:
Method Overloading (Compile-time polymorphism): Multiple methods with the same
•
name but different parameters (number or type) can coexist in the same class.
• Method Overriding (Runtime polymorphism): A subclass can provide a specific
implementation of a method that is already defined in its superclass.
Benefits:
• Flexibility: Allows different objects to respond to the same method call in a way specific
to their type.
• Code maintainability: Makes it easier to modify code or add new functionalities without
affecting the existing system.
Example:
class Animal
{
void sound()
{
[Link]("Animal makes a sound");
}
}
class Dog extends Animal {
@Override
void sound() {
[Link]("Dog barks");
}
}
public class Main {
public static void main(String[] args) {
Animal myAnimal = new Dog(); // Upcasting
[Link](); // Calls the overridden method in Dog class
}
}
USING BLOCKS OF CODE
In Java, blocks of code are sections of code enclosed within curly braces {} that group together
related statements. These blocks are used in various contexts, such as in method definitions,
conditionals, loops, classes, and exception handling. They help structure programs, define the
scope of variables, and control the flow of execution.
Department of Computer Science & Design, ATMECE, MYSURU 5
Module-01 Object Oriented Programming using Java – BCS306A
• Method Block: A method block contains code that is executed when the method is called. The
method block is defined between {} and is used to group related operations together.
• Conditional Block: Conditional blocks are used inside control structures like if, else if, and
else to execute a set of statements when a certain condition is true or false.
• Loop Block: Loops use blocks of code to repeatedly execute a group of statements as long as
a certain condition is met. for, while, and do-while are the common loop structures in Java.
• Class Block: A class block defines a blueprint for objects, containing fields (attributes) and
methods (behaviors). All code inside a class is grouped into the class block.
• Static Block: A static block is a block of code that runs once when the class is loaded into
memory, before the creation of any objects. It is used for static initialization of class-level
variables.
• Try-Catch Block (Exception Handling): Java provides try-catch blocks to handle exceptions
(runtime errors). The try block contains the code that might throw an exception, while the
catch block contains code to handle that exception.
• Synchronized Block: A synchronized block is used to control access to a block of code by
multiple threads, ensuring that only one thread can execute that block at a time.
• Initialization Block (Instance Initializer): Instance initializers are blocks of code that are
executed when an object is created, before the constructor is called. These blocks are used to
initialize instance variables.
Blocks of code in Java enhance program structure, define the scope of variables, manage flow
control, and ensure better readability and maintainability.
LEXICAL ISSUE
lexical issues refer to problems or errors that occur during the lexical analysis phase of compiling
a program. Lexical analysis is the first step in the compilation process where the source code is
broken down into tokens such as keywords, identifiers, literals, operators, and delimiters. If the
code contains invalid tokens or violates the lexical structure of the language, lexical errors occur.
• Whitespace: Whitespace includes spaces, tabs, and newlines, and is generally ignored by the
Java compiler unless it appears within tokens like identifiers or literals.
• Purpose: Used to separate tokens and improve code readability.
• Lexical Issues: Using whitespace within identifiers or literals can cause errors.
int my var = 10; // Invalid: Variable name cannot contain spaces
• Identifiers: Identifiers are names used for variables, methods, classes, etc. They follow
specific rules:
Rules for Identifiers:
• Must begin with a letter (A-Z, a-z), an underscore (_), or a dollar sign ($).
• Subsequent characters can include digits (0-9), letters, underscores, or dollar signs.
• Cannot be a Java keyword or reserved word.
Lexical Issues:
• Using invalid characters in identifiers.
• Starting identifiers with digits.
• Using Java keywords as identifiers
int 1number = 10; // Invalid: Cannot start an identifier with a digit
int class = 20; // Invalid: 'class' is a keyword and cannot be used as an identifier
Department of Computer Science & Design, ATMECE, MYSURU 6
Module-01 Object Oriented Programming using Java – BCS306A
• Literals: Literals represent fixed values in Java, such as numbers, characters, and strings.
There are several types of literals in Java: integer literals, floating-point literals, boolean
literals, character literals, and string literals.
Types of Literals:
• Integer Literals: Represent whole numbers (e.g., 10, 0, -5).
• Floating-Point Literals: Represent decimal numbers (e.g., 3.14, 0.5).
• Boolean Literals: Represent true or false.
• Character Literals: Represent a single character enclosed in single quotes (e.g., 'A').
• String Literals: Represent a sequence of characters enclosed in double quotes (e.g.,
"Hello").
Lexical Issues:
• Incorrectly formatted literals (e.g., forgetting quotes).
• Using invalid escape sequences in strings.
• Using underscores (_) improperly in numeric literals.
char c = "A"; // Invalid: Character literals must use single quotes
int number = 1_000_000_; // Invalid: Underscores cannot be at the end of a numeric literal
• Comments: Comments in Java are non-executable statements used for documentation
purposes. They are ignored by the compiler.
Types of Comments:
• Single-line comment: Starts with //.
• Multi-line comment: Starts with /* and ends with */.
Lexical Issues:
• Forgetting to close multi-line comments.
/* This is a comment // Invalid: Multi-line comment is not closed
int x = 5;
• Separators: Separators are symbols that separate or group individual code elements in Java.
Java uses the following separators:
Common Separators:
• () - Parentheses: Used in method calls and control flow structures.
• {} - Curly Braces: Used for blocks of code.
• [] - Brackets: Used for arrays.
• ; - Semicolon: Ends statements.
• , - Comma: Separates variables in declarations.
• . - Dot: Used to access object members.
Lexical Issues:
• Missing or misplaced separators can cause syntax errors during lexical analysis.
int x = 5 // Invalid: Missing semicolon
if (x > 5 { // Invalid: Missing closing parenthesis
[Link](x);
}
Department of Computer Science & Design, ATMECE, MYSURU 7
Module-01 Object Oriented Programming using Java – BCS306A
• The Java Keywords: Keywords are reserved words in Java that have predefined meanings
and cannot be used as identifiers. Examples include class, int, if, else, for, while, try, catch, etc.
Lexical Issues:
• Using a keyword as an identifier or variable name will result in an error.
• Misspelling keywords (e.g., writing Clas instead of class) can also cause errors.
int if = 10; // Invalid: 'if' is a reserved keyword and cannot be used as an identifier
clas MyClass { // Invalid: 'clas' is not a valid keyword (should be 'class') int x = 5; }
DATA TYPES
Data types specify the different sizes and values that can be stored in the variable. There are two
types of data types in Java:
• Primitive data types: The primitive data types include boolean, char, byte, short, int,
long, float and double.
• Non-primitive data types: The non-primitive data types include Classes, Interfaces,
and Arrays.
Fig 03: Data types available in java
Department of Computer Science & Design, ATMECE, MYSURU 8
Module-01 Object Oriented Programming using Java – BCS306A
• Integer Types: Used for storing whole numbers (without fractions).
Data Type Size Minimum Value Maximum Value Default Value
byte 8 bits -128 127 0
short 16 bits -32,768 32,767 0
int 32 bits -2^31 2^31-1 0
long 64 bits -2^63 2^63-1 0L
long is used when int is not large enough to hold a specific value. It is often used with the suffix L (e.g.,
100L).
• Floating-Point Types: Used for storing numbers with decimal points.
Data Type Size Range Precision Default Value
float 32 bits ±1.4E-45 to ±3.4E38 7 digits 0.0f
double 64 bits ±4.9E-324 to ±1.7E308 15 digits 0.0d
double is the default for decimal values. float requires the suffix f (e.g., 3.14f).
• Character Type: Used for storing a single 16-bit Unicode character.
Data Type Size Range Default Value
char 16 bits 0 to 65,535 '\u0000'
Unicode allows Java to represent international characters like Chinese, Japanese, etc.
• Boolean Type: Represents two possible states: true or false
Data Type Size Values Default Value
boolean 1 bit true, false false
Example: Demonstrating Datatypes available in Java
Department of Computer Science & Design, ATMECE, MYSURU 9
Module-01 Object Oriented Programming using Java – BCS306A
VARIABLES IN JAVA: A variable is a container which holds the value while the Java program is
executed. A variable is assigned with a data type. Variable is a name of memory location. Variables
store data that can be used and manipulated throughout the program. Java variables must be
declared with a data type before use.
There are three types of variables in java: local, instance and static.
1. Local Variables: Declared inside methods, constructors, or blocks. These variables are
not accessible outside their specific method or block.
• No default value; must be initialized before use.
2. Instance Variables: Declared in a class but outside of any method, constructor, or block.
Each object of the class has its own copy.
• Default values depend on the data type (0 for numbers, null for objects).
3. Static Variables: Declared using the static keyword. Shared by all instances of the class.
• Can be accessed directly using the class name without creating an object.
int age = 25; // Declaring and initializing an int variable
double salary = 50000.50; // Declaring and initializing a double variable
Variable Naming Rules:
• Can contain letters, digits, underscores, and dollar signs.
• Must begin with a letter (or _, $).
• No spaces or keywords are allowed.
Example: Demonstrating Variable Types in Java
Department of Computer Science & Design, ATMECE, MYSURU 10
Module-01 Object Oriented Programming using Java – BCS306A
Type Conversion and Type Casting
The two terms type casting and the type conversion are used in a program to convert one data
type to another data type. The conversion of data type is possible only by the compiler when they
are compatible with each other.
If a data type is automatically converted into another data type at compile time is known as type
conversion. The conversion is performed by the compiler if both data types are compatible with
each other. Remember that the destination data type should not be smaller than the source type.
It is also known as widening conversion of the data type.
When a data type is converted into another data type by a programmer or user while writing a
program code of any programming language, the mechanism is known as type casting. The
programmer manually uses it to convert one data type into another. It is used if we want to change
the target data type to another data type. Remember that the destination data type must be
smaller than the source data type. Hence it is also called a narrowing conversion.
SLNO TYPE CASTING TYPE CONVERSION
Type casting is a mechanism in which one Type conversion allows a compiler to
1 data type is converted to another data type convert one data type to another data type
using a casting () operator by a programmer. at the compile time of a program or code.
Type conversion is only used with
It can be used both compatible data type and
2 compatible data types, and hence it does not
incompatible data type.
require any casting operator.
It does not require any programmer
It requires a programmer to manually casting intervention to convert one data type to
3
one data into another type. another because the compiler automatically
compiles it at the run time of a program.
It is used while designing a program by the It is used or take place at the compile time of
4
programmer. a program.
When casting one data type to another, the When converting one data type to another,
5 destination data type must be smaller than the destination type should be greater than
the source data. the source data type.
It is also known as narrowing conversion It is also known as widening conversion
6 because one larger data type converts to a because one smaller data type converts to a
smaller data type. larger data type.
7 It is more reliable and efficient. It is less efficient and less reliable.
In type conversion, data is unlikely to be lost
There is a possibility of data or information
8 when converting from a small to a large data
being lost in type casting.
type.
float b = 3.0; int x = 5, y = 2, c;
9
int a = (int) b float q = 12.5, p; p = q/x;
Department of Computer Science & Design, ATMECE, MYSURU 11
Module-01 Object Oriented Programming using Java – BCS306A
Arrays: Array is an object which contains elements of a similar data type. In Java, an array is a
data structure that allows you to store multiple values of the same type in a single variable. It is a
fixed-size, ordered collection of elements that can be accessed using an index.
Array in Java is index-based, the first element of the array is stored at the 0th index, 2nd element
is stored on 1st index and so on.
Declaration and Initialization
• Declaration: To declare an array, you specify the type of elements it will hold, followed by
square brackets.
Syntax
o datatype[ ] arrayname;
o datatype arrayname [ ];
o datatype [ ]arrayname;
• Initialization: You can initialize an array at the time of declaration or separately.
o Static Initialization:
int[] numbers = {1, 2, 3, 4, 5};
o Dynamic Initialization:
int[] numbers = new int[5];
• Accessing Array Elements: Array elements can be accessed using their index, which
starts at 0.
int firstElement = numbers[0]; // Accessing the first element
numbers[1] = 10; // Modifying the second element
• Array Length: The length of an array can be found using the length property.
int length = [Link]; // Gets the length of the array
Multidimensional Arrays
Java also supports multidimensional arrays, primarily two-dimensional arrays (matrices).
Declaration and Initialization:
int[][] matrix = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
Common Operations
• Traversing an Array: You can use a loop to iterate over an array.
• Enhanced For Loop: Java provides a simpler way to iterate through arrays.
Refer: LAB: Program-01
Department of Computer Science & Design, ATMECE, MYSURU 12
Module-01 Object Oriented Programming using Java – BCS306A
OPERATORS
Operators are special symbols or keywords in programming languages that are used to perform
operations on variables and values. They are fundamental building blocks that allow you to
manipulate data, control the flow of a program, and perform calculations.
Types of Operators
1. Arithmetic Operators: Used to perform mathematical calculations, such as addition,
subtraction, multiplication, and division.
Operator Description Example
+ Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division a/b
% Modulus (remainder) a%b
Example Snippet
2. Relational Operators: Used to compare two values or expressions. They return a boolean
result (true or false).
Operator Description Example
== Equal to a == b
!= Not equal to a != b
> Greater than a>b
< Less than a<b
>= Greater than or equal to a >= b
<= Less than or equal to a <= b
Example Snippet:
3. Boolean Logical Operators: Boolean logical operators are used to combine multiple
boolean expressions
Operator Description Example
&& Logical AND a && b
` `
! Logical NOT !a
Example Snippet
Department of Computer Science & Design, ATMECE, MYSURU 13
Module-01 Object Oriented Programming using Java – BCS306A
4. Bitwise Operators: Operate on binary representations of integers, allowing
manipulation of individual bits.
o & (AND), | (OR), ^ (XOR), ~ (NOT), << (left shift), >> (right shift)
5. Assignment Operators: Used to assign values to variables. These can also include
compound assignment operators that combine an arithmetic operation with an
assignment.
Operator Description Example
= Assigns the right-hand value to the a = 10
left-hand variable
Compound Assignment Operators:
Operator Description Example
+= Add and assign a += 5 (same as a = a + 5)
-= Subtract and assign a -= 3 (same as a = a - 3)
*= Multiply and assign a *= 2 (same as a = a * 2)
/= Divide and assign a /= 2 (same as a = a / 2)
%= Modulus and assign a %= 2 (same as a = a % 2)
Example Snippet
6. Ternary Operator: A shorthand for if-else statements that evaluates a condition and
returns one of two values based on whether the condition is true or false.
condition ? expression1 : expression2
Example Snippet
7. Unary Operators: Operate on a single operand to produce a new value. These can include
incrementing, decrementing, negating, etc.
o ++, --, - (unary negation)
8. Logical Operators: Used to combine multiple boolean expressions and perform logical
operations.
o && (AND), || (OR), ! (NOT)
9. Instanceof Operator: Used to test whether an object is an instance of a specific class or
subclass.
o object instanceof ClassName
Department of Computer Science & Design, ATMECE, MYSURU 14
Module-01 Object Oriented Programming using Java – BCS306A
Operator Precedence
Operator precedence determines the order in which operators are evaluated in an expression.
Higher precedence operators are evaluated first.
• Common Precedence (from highest to lowest):
1. Parentheses ()
2. Unary operators ++, --, -, +, !
3. Multiplication, Division, Modulus *, /, %
4. Addition, Subtraction +, -
5. Relational operators <, >, <=, >=, ==, !=
6. Logical AND &&
7. Logical OR ||
8. Assignment =
Using Parentheses: Using parentheses can clarify expressions and override the default
precedence.
Example Snippet
Department of Computer Science & Design, ATMECE, MYSURU 15
Module-01 Object Oriented Programming using Java – BCS306A
CONTROL STATEMENTS IN JAVA
Control statements allow you to dictate the flow of execution in your Java programs. They can be
categorized into three main types: selection statements, iteration statements, and jump
statements.
1. Selection Statements: Selection statements enable the program to execute different blocks
of code based on certain conditions.
• if Statement: The if statement evaluates a boolean expression. If the expression is true, it
executes the block of code within the statement.
Syntax and Code Snippet
• switch Statement: The switch statement allows you to evaluate a variable against a list of
values (cases). It is useful when you have multiple conditions based on the same variable.
Syntax and Code Snippet
Department of Computer Science & Design, ATMECE, MYSURU 16
Module-01 Object Oriented Programming using Java – BCS306A
2. Iteration Statements: Iteration statements allow you to execute a block of code multiple
times.
• while Loop: The while loop continues to execute as long as the specified condition is true.
Syntax and Code Snippet
• do-while loop: The do-while loop is similar to the while loop, but it guarantees that the code
block will execute at least once, as the condition is checked after the execution.
Syntax and Code Snippet
• for Loop: The for loop provides a concise way to iterate through a range of values.
Syntax and Code Snippet
• For-Each Loop: The for-each loop is specifically used to iterate over arrays or collections. It
simplifies the iteration process.
Syntax and Code Snippet
Department of Computer Science & Design, ATMECE, MYSURU 17
Module-01 Object Oriented Programming using Java – BCS306A
• Local Variable Type Inference in a For Loop: From Java 10 onwards, you can use var to infer
the type of the loop variable.
Syntax and Code Snippet
• Nested Loops: You can also nest loops inside one another to perform more complex
iterations.
Syntax and Code Snippet
3. Jump Statements: Jump statements are used to alter the flow of control within loops or
switch statements.
• break Statement: The break statement is used to exit a loop or switch statement prematurely.
Syntax and Code Snippet
• continue Statement: The continue statement skips the current iteration of a loop and
continues with the next iteration.
Syntax and Code Snippet
• return Statement: The return statement is used to exit from a method and optionally return
a value.
Syntax and Code Snippet
Department of Computer Science & Design, ATMECE, MYSURU 18