DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Demonstrate the use of final, finally, and finalize in Java

  1. #1
    Join Date
    Apr 2020

    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.


    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*/


    lass FinallyExample {
    public static void main(String args[]){
    try {
    int x=100;
    catch(Exception e) {
    finally {
    System.out.println("finally block is executing");}


    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;

  2. #2
    Thank you. I've just started learning Java. I see that this forum will be useful for me.

Similar Threads

  1. Replies: 0
    Last Post: 08-23-2005, 12:28 PM
  2. Cannot overload the Finalize() method, why ?
    By Louis-Philippe Carignan in forum .NET
    Replies: 1
    Last Post: 02-15-2002, 03:26 PM
  3. gc VS finalize()
    By godspeed in forum Java
    Replies: 0
    Last Post: 11-27-2001, 09:28 PM
  4. When is finalize() method gets executed?
    By Lim Wing Hoe in forum Java
    Replies: 4
    Last Post: 10-25-2000, 10:55 AM
  5. forcing a finalize method to run
    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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center