Docsity

lab report of object oriented programming, Lab Reports of Object Oriented Programming

Toggle sidebar
bg1
Experiment No. : 7.1
Title: Write a Java program to find number using final keyword.
Objective: To write a java program using final keyword to find restore number
which are initialized by an array.
Tools: Online Editor (w3schools.com)
Theory: Final'keyword is used in different contexts. First of all,'final'is a'non-
access modifier'applicable only to a variable, a method, or a class. The following
are different contexts where final is used. When a variable is declared with
the'final keyword, its value can’t be modified, essentially, a constant.
Source Code:
class finalnumber
{
public static void main(String[] args)
{
// Declaring and initializing.
int arr[] = { 1, 2, 3 };
//Restore initializing value in final number.
for (final int i : arr)
System.out.print(i + " ");
}
}
pf3
pf4
pf5

Partial preview of the text

Download lab report of object oriented programming and more Lab Reports Object Oriented Programming in PDF only on Docsity!

Experiment No. : 7.

Title: Write a Java program to find number using final keyword.

Objective: To write a java program using final keyword to find restore number

which are initialized by an array.

Tools: Online Editor (w3schools.com)

Theory: Final keyword is used in different contexts. First of all, final is a non-

access modifier applicable only to a variable, a method, or a class. The following are different contexts where final is used. When a variable is declared with the final keyword, its value can’t be modified, essentially, a constant.

Source Code:

class finalnumber { public static void main(String[] args) { // Declaring and initializing. int arr[] = { 1, 2, 3 }; //Restore initializing value in final number. for (final int i : arr) System.out.print(i + " "); } }

Output:

Discussion:

  1. A final method cannot be overridden.
  2. The Object class does-these numbers of its methods are final.
  3. We must declare methods with the final keyword for which we are required to follow the same implementation throughout all the derived classes.

//finally block Finally { System.out.println("Finally block."); } } }

Output:

Discussion:

  1. If an exception does not occur in try block then control flow will be finally block followed by rest of the program.

Southern University Bangladesh

Department of Computer Science and Engineering

Lab-

Course Name: Object Oriented Programming Lab

Course Code: CS

Fall 2022

Name : Abu Saied Mohammad Tarek ID : 666-46- Batch : 46 th E-mail ID : [email protected] Date of Assignment : 18-10- Date of Submission : 25-10- Contact No. : 01841- Signature of Student : Course Teacher : Nishu Chowdhury (Lecturer)