0% found this document useful (0 votes)
257 views

JPR Practical Assignment 12 Solution

The document demonstrates the use of the final keyword in Java. It shows code for a class hierarchy without using final, which allows overriding and changing the value of a variable. Using final prevents overriding and keeps the variable value constant. The output differs depending on whether final is used or not.

Uploaded by

sakshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
257 views

JPR Practical Assignment 12 Solution

The document demonstrates the use of the final keyword in Java. It shows code for a class hierarchy without using final, which allows overriding and changing the value of a variable. Using final prevents overriding and keeps the variable value constant. The output differs depending on whether final is used or not.

Uploaded by

sakshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. WAP to demonstrate use of final keyword.

 Without final :

import java.io.*;

class one

{ int a=10;

void A()

{ System.out.println("\n*****Welcome***");

class two extends one

{ void A()

{ a=20;

System.out.println("\nBye");

System.out.println(+a);

class p27

{ public static void main(String[] arg)

{ System.out.println("\n*******Without final :******* ");

two b=new two();

b.A();

 Output :
 Using final keyword :

import java.io.*;

final class one

{ final int a=10;

final void A()

{ System.out.println("\n*****Welcome***");

class two extends one

{ void A()

{ a=20;

System.out.println("\nBye");

System.out.println(+a);

class p27

{ public static void main(String[] arg)

{ System.out.println("\n*******Using final :******* ");

two b=new two();

b.A();

 Output :

You might also like