Q - Instance variables and instance methods can be accessed
using an object as the access
mechanism. What is the difference in the syntax used to
access an instance variable and an
instance method.
A - None. There is essentially no difference in the syntax
used to access a variable or a method.
Q - Once you have instantiated an object, it is always
possible to access all of the instance
variables and instance methods of that object by joining the
name of the object to the name of the
variable or method using a period: True or False? If false,
explain why.
A - False. Sometimes variables or methods may be hidden so
as to make it impossible to access them. It is very common to hide the
variables and to provide methods which can be accessed to serve as a pathway to
the variables.
Q - Given an object named obj that has a public instance
method named myMethod(), provide a
code fragment that shows the proper syntax for accessing the
method.
A - The proper syntax for accessing an instance method named
myMethod() follows:
obj.myMethod()
Q - The object-oriented approach normally recommends hiding
instance variables behind access
methods: True or False? If true, explain why.
A - True. The object-oriented approach normally recommends
hiding instance variables behind access methods. There are a variety of reasons
why. One important reason is that hiding the instance variables makes it
possible to later modify the implementation of instance variables to improve
the behavior of objects of the class, without a requirement for modifying code
that uses the clsss, provided that the access methods are not modified.
Q - The returning of memory (to the operating system)
occupied by objects that are no longer
needed is automatically accomplished in Java by a feature
commonly known as the
____________________.
A - The returning of memory to the operating system is taken
care of automatically by a feature of Java known as the garbage collector.
Q - All necessary cleanup in a Java program is performed
automatically by the garbage collector:
True or False? If false, explain why.
A - False. Java does not support anything like a destructor
that is guaranteed to be called whenever the object is no longer needed.
Therefore, other than returning allocated memory, it is the responsibility of
the programmer to explicitly perform any other required cleanup at the
appropriate point in time.
Q - When does an object become eligible for garbage
collection?
A - An object becomes eligible for garbage collection when
there are no more references to that object.
Q - What can your program do to purposely make an object
eligible for garbage collection.
0 comments:
Post a Comment