Java Questions 11 - 20  «Prev  Next»

Java Questions 17 - Class and Object Creation

  1. What are 3 ways to access a method?
    Answer:
    1. Invoking a method declared in the same class.
    2. Invoking a method using a reference in the class.
    3. Invoking an inherited method.
  2. What do the words 1) construct, 2) create, and 3) instantiate mean when used interchangeably?
    Answer:
    They all mean, "An object is built on the heap."
  3. What is the value of a reference that has not had an object assigned to it?
    Answer:
    The value of the reference is Null.
  4. How can you determine if a method or variable is static?
    Answer:
    If you see a method invoked ( or a variable accessed) without the dot operator (.) , it means the method or variable belongs to the class where you see that code.
  5. What does the reference always refer to?
    Answer:
    The reference this always refers to the currently executing object.
  6. Can a private member be inherited from a subclass?
    Answer:
    When a member is declared private, a subclass cannot inherit it.
  7. Does a subclass know about the private methods in the superclass?
    Answer:
    A subclass is unaware of the private mtehods in the superclass.
  8. Why is default access called package access?
    Answer:
    A default member may be accessed only if the class accessing the member belongs to the same package, whereas a protected member can be accessed (through inheritance) by a subclass even if the subclass is in a different package.
  9. What differentiates default and protected behavior ?
    Answer:
    Default and protected behavior differ only when we talk about subclasses. If the protected keyword is used to define a member, any subclass of the class declaring the member can access it through inheritance.
  10. How would you decribe default access?
    Answer:
    Default access does not allow a subclass to access a superclass member unless the subclass is in the same package as the superclass.