Final object in Java

0
131

This tutorial is all about Final Object in Java. We cannot reinitialized Final Objects in Java. For Example: See the below code

[java]

class P{

int i ;

}

class Manager{

public static void main(String args[]) {

final P p1=new P();

P.i=10; //modifying i not p1 , allowed in Java

System.out.println (“compile time success”);

}

}

[/java]

Above code will work fine.

See another example, here you will get error

[java]

class Q {

int i ;

}

class Manager {

public static void main (String args[] )

{

final Q q1=new Q();

q1=new Q(); // compile time error

}

}

[/java]

 

Readers might Read also:

 

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.