Results 1 to 4 of 4
  1. #1
    money123 is offline Member
    Join Date
    Jul 2007
    Posts
    11
    Rep Power
    0

    Default confused with protected qualifier.....plz solve this query...

    Class "Foo" resides in package "com.foo" and contains
    methods with the following declarations:

    a. final String getName()
    b. protected final String getDescription()
    c. private String getCode()
    d. synchronized String getFilename()
    e. String getID()

    Class "Bar" extends "Foo" and resides in package
    "com.foo.bar"

    Referring to the scenario above, which one of the methods of "Foo" is accessible to class "Bar"?

    Choice 1

    Method a
    Choice 2

    Method b
    Choice 3

    Method c
    Choice 4

    Method d
    Choice 5

    Method e

    I think its either answer a or b:confused:

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Only B is accessible to the Bar class. The other methods have what is called package scope. Look here

  3. #3
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    Access modifier
    - private = available only inside it's own class
    - default (no modifier) = available inside it's own class and subclasses residing in the same directory only
    - protected = available inside it's own class and subclasses anywhere
    - public = available publically, no limitation

    Foo methods that are accessible to the Bar class are
    a aren't accessible, since it's access modifier are default n bar located in another directory
    b are accessible
    c aren't accesible, its private
    d aren't accesible, synchronized aren't an access modifier, its used for thread synchronization, the access modifier for the method are default
    e aren't available, having a default modifier

    I hope this isn't some kinda homework :p
    But if i were supposed to pick one, i'll pick the one with the less limitation, choice 2 ==> b
    Hope this helps :D
    Last edited by cruxblack; 07-28-2007 at 04:15 PM.

  4. #4
    money123 is offline Member
    Join Date
    Jul 2007
    Posts
    11
    Rep Power
    0

    Default

    thankyou so much....
    this is not a homework but a test in which i appeared...
    so was confused with my answer......
    but now clarified.....txx:) :)

Similar Threads

  1. Reading URLs Protected with HTTP Authentication
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:58 PM
  2. A great doubt in Java Applet,will u solve it!!
    By anithababu in forum Java Applets
    Replies: 6
    Last Post: 01-27-2008, 02:20 PM
  3. Help mi solve my error
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-11-2008, 06:26 AM
  4. Cannot solve the coding problem of my assignment
    By elimmom in forum New To Java
    Replies: 3
    Last Post: 08-13-2007, 12:33 PM
  5. help with protected method in vector class
    By katie in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 11:59 PM

Posting Permissions

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