AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: buturab — October 6, 2006
    -12 votes
      + -

    Public methods and variables can be used by any other class without having to create an instance of that class
    eg:
    (Toy.java) and (Fun.java) are two public classes. Toy.java has a method car() in it. In order for Fun.java to use it it should do the following to invoke the method
    Toy.car()

    Private methods and variables of a class (Toy.java) can only be used by another class (Fun.java) by creating an instance of that class.
    eg: Toy.java has a method car() in it. In order For Fun.java to use it it should do the following to invoke the method
    Tou toy = new Toy()
    toy.car()

    A Protected variable or method can only be accessed by the classes that extend it (ie by using inheritance)

  2. Submitted By: manta — October 6, 2006
    +9 votes
      + -

    Unfortunately I believe that buturab is discussing Static vs. non-Static methods and variables. In the case of Public, Private and Protected, that is used to describe which programs can access that class or method:

    Public – any other class from any package can instantiate and execute the classes and methods
    Protected – only subclasses and classes inside of the package can access the classes and methods
    Private – the original class is the only class allowed to executed the methods.

  3. Submitted By: Radha — October 6, 2006
    +5 votes
      + -

    And in case if there is no modifiers specified, it means, only the classes
    inside the package can access this class and its methods

  4. Submitted By: mandeepk — October 6, 2006
    +4 votes
      + -

    To add to Radha’s comment, default access specifier is also called “Friendly”

  5. Submitted By: Mohit — October 6, 2006
    -2 votes
      + -

    Manta is absolutely right !
    I have double checked the answers from the book.
    Good work Manta !!!!

  6. Submitted By: Ryan J. McDonough — October 10, 2006
    +0 votes
      + -

    buturab, one correction on protected methods: they may also be accessed by other classes in the same package.

  7. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.