-
Demonstrate the use of final, finally, and finalize in Java
Hello Everyone, I have completed my java certification and I am preparing myself for my upcoming interviews. I am finding the code examples to demonstrate the use of final, finally, and finalize. I have written some code which I mention below. Can anyone check it or suggest me is it right? I am preparing myself for an upcoming java interview and also looking to trending java questions. I am preparing 100 questions list from here and looking to more because I don't wanna lose any opportunity.
Final:
class FinalVarExample {
public static void main( String args[])
{
final int a=10;
a=50; /* Will result in an error as the value can’t be changed now*/
}
Finally:
lass FinallyExample {
public static void main(String args[]){
try {
int x=100;
}
catch(Exception e) {
System.out.println(e);
}
finally {
System.out.println("finally block is executing");}
}
}
}
Finalize:
class FinalizeExample {
public void finalize() {
System.out.println("Finalize is called");
}
public static void main(String args[])
{
FinalizeExample f1=new FinalizeExample();
FinalizeExample f2=new FinalizeExample();
f1= NULL;
f2=NULL;
System.gc();
}
}
-
Thank you. I've just started learning Java. I see that this forum will be useful for me.
Similar Threads
-
Replies: 0
Last Post: 08-23-2005, 12:28 PM
-
By Louis-Philippe Carignan in forum .NET
Replies: 1
Last Post: 02-15-2002, 03:26 PM
-
By godspeed in forum Java
Replies: 0
Last Post: 11-27-2001, 09:28 PM
-
By Lim Wing Hoe in forum Java
Replies: 4
Last Post: 10-25-2000, 10:55 AM
-
By new2java in forum Java
Replies: 1
Last Post: 05-08-2000, 10:31 AM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|