A protected member of a class may be directly accessed by Select one: a. Methods
ID: 3684697 • Letter: A
Question
A protected member of a class may be directly accessed by
Select one:
a. Methods of the same class
b. Methods of a subclass
c. Methods in the same package
d. All of these
Question 2
A subclass class can directly access
Select one:
a. All members of the superclass class
b. Only public and private members of the superclass class
c. Only protected and private members of the superclass class
d. Only public and protected members of the superclass class
Question 3
All fields declared in an interface
Select one:
a. Are final and static
b. Have protected access
c. Must be initialized in the class implementing the interface
d. Have private access
Question 4
Given the following code which of the following is true?
Select one:
a. ClassA must override each method in ClassB
b. ClassB must override each method in ClassA
c. ClassB is derived from ClassA
d. ClassA is derived from ClassB
Question 5
If a class contains an abstract method,
Select one:
a. You must create an instance of the class
b. The method will have only a header, but not a body, and end with a semicolon
c. The method cannot be overridden in derived classes
d. All of these
Question 6
If a subclass constructor does not explicitly call a superclass constructor,
Select one:
a. It must include the code necessary to initialize the superclass fields
b. The superclass fields will be set to the default values for their data types
c. Java will automatically call the superclass's default constructor immediately after the code in the subclass's constructor executes
d. Java will automatically call the superclass's default constructor just before the code in the subclass's constructor executes
Question 7
If a superclass does not have a default constructor,
Select one:
a. Then a class that inherits from it, must initialize the superclass values
b. Then a class that inherits from it, must call one of the constructors that the superclass does have
c. Then a class that inherits from it, does not inherit the data member fields from the superclass
d. Then a class that inherits from it, must contain the default constructor for the superclass
Question 8
If you do not provide an access specifier for a class member, the class member is given this access by default.
Select one:
a. Private
b. Public
c. Protected
d. Package
Question 9
If ClassA is derived from ClassB, then
Select one:
a. Public and private members of ClassB are public and private, respectively, in ClassA
b. Public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA
c. Neither public or private members in ClassB can be directly accessed in ClassA
d. Private members in ClassB are changed to protected members in ClassA
Question 10
In a class hierarchy
Select one:
a. The more general classes are toward the bottom of the tree and the more specialized are toward the top
b. The more general classes are toward the top of the tree and the more specialized are toward the bottom
c. The more general classes are toward the left of the tree and the more specialized are toward the right
d. The more general classes are toward the right of the tree and the more specialized are toward the left
Question 11
In an interface all methods have
Select one:
a. Private access
b. Protected access
c. Public access
d. Packaged access
Question 12
In the following statement, which is the interface?
Select one:
a. ClassA
b. ClassB
c. ClassC
d. Cannot tell
Question 13
In the following statement, which is the subclass?
Select one:
a. ClassA
b. ClassB
c. ClassC
d. Cannot tell
Question 14
In the following statement, which is the superclass?
Select one:
a. ClassA
b. ClassB
c. ClassC
d. Cannot tell
Question 15
In UML diagrams, inheritance is shown
Select one:
a. With a line that has an open arrowhead at one end that points to the superclass
b. With a line that has an open arrowhead at one end that points to the subclass
c. With a line that has a closed arrowhead at one end that points to the superclass
d. With a line that has a closed arrowhead at one end that points to the subclass
Question 16
Look at the following code and determine what the call to super will do.
Select one:
a. This cannot be determined form the code
b. It will call the constructor of ClassA that receives an integer as an argument
c. It will call the method super and pass the value 40 to it as an argument
d. The method super will have to be defined before we can say what will happen
Question 17
Look at the following code. The method in line ________ will override the method in line ________.
Select one:
a. 4, 10
b. 5, 11
c. 10, 4
d. 11, 5
Question 18
Look at the following code. What is missing from ClassA?
Select one:
a. It does not override methodA
b. It does not have a constructor
c. It does not overload methodA
d. It is a complete class
Question 19
Question text
Look at the following code. Which line has an error?
Select one:
a. 1
b. 2
c. 3
d. 4
Question 20
Look at the following code.
Which method will be executed as a result of the following statements?
Select one:
a. Line 4
b. Line 9
c. Line 14
d. This is an error and will cause the program to crash
Question 21
Protected members are
Select one:
a. Not quite private
b. Not quite public
c. Both Not quite private and Not quite public
d. Neither Not quite private nor Not quite public
Question 22
What is wrong with the following code?
Select one:
a. Nothing is wrong with the code
b. The method super is not defined
c. The call to the method super must be the first statement in the constructor
d. No values may be passed to super
Question 23
Which of the following statements declares Salaried as a subclass of PayType?
Select one:
a. public class Salaried extends PayType
b. public class Salaried implements PayType
c. public class Salaried derivedFrom(Paytype)
d. public class PayType derives Salaried
Question 24
Every class has a toString method and an equal's method inherited from the Object class.
Select one:
True
False
Question 25
If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method.
Select one:
True
False
Explanation / Answer
1)
The protected members are visible to classes in the same package and to sub classes.
Therefore the correct option is “d. All of these”.
2)
Therefore the correct option is “d. Only public and protected members of the superclass class ”.
3)
Therefore the correct option is “a. Are final and static”.
4)
Code is missed for question 4.
5)
Therefore the correct option is “b. The method will have only a header, but not a body, and end with a semicolon”.
6)
The correct option is “d. Java will automatically call the superclass's default constructor just before the code in the subclass's constructor executes”
7)
The correct option is “b. Then a class that inherits from it, must call one of the constructors that the superclass does have”
8)
The correct option is “public”.
9)
Therefore the correct option is “b. Public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA”.
10)
Therefore the correct option is “b. The more general classes are toward the top of the tree and the more specialized are toward the bottom”.
11)
Therefore correct option is “c. Public access”
15)
Therefore the correct option is “a. With a line that has an open arrowhead at one end that points to the superclass”.
21)
Therefore the correct option is “c. Both Not quite private and Not quite public”.
23)
Therefore the correct option is “a. public class Salaried extends PayType ”.
24)
Therefore the given statement is “True”.
25)
Therefore the given statement is “ False”.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.