QUESTIONS AND ANSWERS GRADED A+
◉An instance variable declaration consists of ______?
a) the return type, the name of the method, and a list of the
parameters (if any).
b) an access specifier, the type of the instance variable, and the name
of the instance variable.
c) an access specifier, a list of the parameters (if any), and the body
of the method.
d) the type of the instance variable, an access specifier, a list of the
parameters (if any), and the body of the method.. Answer: b
◉Which of the following is NOT part of the declaration of an
instance variable?
a) the return type
,b) a modifier specifying the level of access
c) the data type
d) the name. Answer: a
◉Which of the following statements is true regarding classes?
a) Each object of a class has a separate copy of each instance
variable.
b) All objects created from a class share a single set of instance
variables.
c) Private instance variables can be accessed by any user of the
object.
d) Public instance variables can be accessed only by the object itself..
Answer: a
◉Consider the following code snippet:
public class Coin
{
private String coinName;
...
}
,Which of the following statements is correct?
a) The coinName variable can be accessed by any user of a Coin
object.
b) The coinName variable can be accessed only by methods of the
Coin class.
c) The coinName variable can be accessed only by methods of
another class.
d) The coinName variable cannot be accessed at all because it is
private.. Answer: b
◉Consider the following code snippet:
public class Coin
{
private String coinName;
public String getCoinValue()
{...}
}
Which of the following statements is correct?
, a) The getCoinValue method can be accessed by any user of a Coin
object.
b) The getCoinValue method can be accessed only by methods of the
Coin class.
c) The getCoinValue method can be accessed only by methods of
another class.
d) The getCoinValue method cannot be accessed at all.. Answer: a
◉Consider the following code snippet:
public class Employee
{
private String empName;
...
}
Which of the following statements is correct?
a) The empName variable can be accessed by any user of an
Employee object.
b) The empName variable can be accessed only by methods of the
Employee class.