• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Queries

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All.

here is my question.

Which of the following statements are true?
1.To be overridden a method must have the same name, parameter types and return type
2.It is possible to override methods in a superclass or the same class
3.classes that are marked as final may not be extended. - true
4.an overriding method cannot have more access (be more public) than the method being overriden.

  • [list]As of java 1.4 option 1 is correct. what would be the statement as of java 5.0 then?
  • option 4 - quite confused with the terms overriding and overriden.


  • thanks
    Anvi
     
    Ranch Hand
    Posts: 1710
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Anvi,

    Good catch,


    # As of java 1.4 option 1 is correct. what would be the statement as of java 5.0 then?
    # option 4 - quite confused with the terms overriding and overriden.



    With Java 5.0 the statement should be:


    To be overridden a method must have the same name, parameter types and return type except covariant return allowed with Java 5.0;



    Anvi, if this sort of question is asked, we will be getting clear idea from the question itself. What is required for us to understand the covariant return, Java 1.4(restriction) and 1.5(covariant).


    option 4 - quite confused with the terms overriding and overriden.



    True fact:

    an overriding method cannot have more access (be more public) than the method being overriden. [FALSE]
    See the example


    B overrides the method go() with protected access (class A's go() method
    has default access)
    Same in the case of method come. (protected to public overriding)



    Regards,
    cmbhatt
     
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Which of the following statements are true?
    1.To be overridden a method must have the same name, parameter types and return type
    2.It is possible to override methods in a superclass or the same class
    3.classes that are marked as final may not be extended. - true
    4.an overriding method cannot have more access (be more public) than the method being overriden.

    Anvi,

    1. The overridden method must have the same name, parameter types. It can have the same return type or covarient types.
    2. Its not possible to override methos in the same class
    3. ....
    4. class X{
    String aMethod(){System.out.println("In Super class");}
    }

    class Y extends X{
    private String aMethod(){System.out.println("In Super class");} //gives error as the access is restricted
    }


    Thanks
     
    Ranch Hand
    Posts: 7729
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Marcus Green's Qustion Of the Day site is based upon SCJP 5.0 now. He explains the reason as to why option 1 is no longer correct for SCJP 5.0. Did you not read the solution?

    As to option 4: it would be correct if it said more private rather than more public.
     
    What are your superhero powers? Go ahead and try them on this tiny ad:
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic