Results 1 to 3 of 3
  1. #1
    esolve is offline Member
    Join Date
    Mar 2015
    Posts
    56
    Rep Power
    0

    Default override/hide a final method in super class.

    Java Code:
    class Father(){
        final void func(){..} 
    }
    Java Code:
    class Son extends Father(){
        void func(){
             super.func();
        }
    }
    my question is:
    1) since func() in the class Father is final, it can't be override, is it correct in grammar for us to define the void func() in the Son class?
    2) if so, is this called hide?


    why do I ask this question, coz, the father here is actually HibernateDaoSupport, it has a final method: setSessionFactory()
    if I want want to use it, like


    Java Code:
    class MyDao extends HibernateDaoSupport{
    
              @resource(name="sessionFactory")
              SessionFactory sessionFactory;
    
         
              setSessionFactory(SessionFactor sessionFactory){
                    super.setSessionFactory(sessionFactory);
              }
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: override/hide a final method in super class.

    In your earlier example you would get a compiler error because you are attempting to override an inherited final method. Why did you repost the question?

    Regards,
    Jim
    Last edited by jim829; 12-23-2015 at 05:16 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: override/hide a final method in super class.

    I've closed the other thread.

    Why do you want to Override setSessionFactory (which you can't, but the question still stands)?
    In your example you are not doing anything with it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. override/hide a final method in super class.
    By esolve in forum New To Java
    Replies: 2
    Last Post: 12-23-2015, 09:15 AM
  2. Replies: 10
    Last Post: 01-09-2012, 08:57 PM
  3. Replies: 1
    Last Post: 10-17-2011, 01:00 AM
  4. Replies: 5
    Last Post: 01-26-2011, 06:38 PM
  5. Override class method
    By Mekie in forum New To Java
    Replies: 8
    Last Post: 11-01-2010, 06:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •