CODE
CLAN JAVA
PROGRAMMING
CLUB
In Java, Access modifiers help to restrict the scope of a class, constructor,
variable, method, or data member. It provides security, accessibility, etc to the
user depending upon the access modifier used with the element.
Types of Access Modifiers in Java
There are four types of access modifiers available in Java:
• Default – No keyword required
• Private
• Protected
• Public
1. Default Access Modifier
When no access modifier is specified for a class, method, or data
member – It is said to be having the default access modifier by default. The
data members, classes, or methods that are not declared using any access
modifiers i.e. having default access modifiers are accessible only within the
same package.
2. Private Access Modifier
The private access modifier is specified using the
keyword private. The methods or data members declared as private are
accessible only within the class in which they are declared.
3. Protected Access Modifier
The protected access modifier is specified using the
keyword protected. The methods or data members declared as protected
are accessible within the same package or subclasses in different packages.
4. Public Access modifier
The public access modifier is specified using the keyword public.
•The public access modifier has the widest scope among all other access
modifiers.
•Classes, methods, or data members that are declared as public are accessible
from everywhere in the program. There is no restriction on the scope of
public data members.
CONTROL STATEMENTS
Java provides statements that can be used to control the flow of
Java code. Such statements are called control flow statements.
It is one of the fundamental features of Java, which provides a
smooth flow of program.
CONTROL STATEMENTS
Java provides three types of control flow statements.
Decision Making statements
Loop statements
Jump statements
DECISION MAKING
Decision-making statements decide which statement to execute and
when.
Control the program flow depending upon the result of the
condition provided.
There are two types of decision-making statements in Java, i.e.,
1. If statement
2. Switch statement.
If Statement:
In Java, the "if" statement is used to evaluate a condition .The
condition of the If statement gives a Boolean value, either true or
false. In Java, there are four types of if-statements given below.
[Link] if statement
[Link]-else statement
[Link]-else-if ladder
[Link] if-statement
1) Simple if statement:
It is the most basic statement among all control flow statements in Java.
It evaluates a Boolean expression and enables the program to enter a block of code
if the expression evaluates to true.
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.
3) if-else-if ladder:
The if-else-if statement contains the if-statement followed by multiple else-if
statements.
In other words, we can say that it is the chain of if-else statements where the
program may enter in the block of code where the condition is true.
We can also define an else statement at the end of the chain.
4. Nested if-statement
In nested if-statements, the if statement can contain a if or if-else statement
inside another if or else-if statement.
4. Nested if-statement
In nested if-statements, the if statement can contain a if or if-else statement
inside another if or else-if statement.
[Link](“THANK YOU”);
Afza Fathima
Gunaseelan R
Final Year Dept of Information Technology
gunaseelan.it20@[Link]
8838965059