Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Multiple questions 1)In which of the following cases is a class member myVariabl

ID: 2247497 • Letter: M

Question

Multiple questions

1)In which of the following cases is a class member myVariable invisible to a method myMethod?

myMethod is a method in the same class and myVariable is private

myMethod is a package-friendly method and myVariable is not private

myMethod is a method in another class and myVariable is public

myMethod is a method in another class and myVariable is private

none of the above

2)The Comparable interface is implemented by some class and alpha and beta are objects of that class. Under what circumstance will alpha.compareTo(beta) return a negative integer?

alpha comes before beta.

alpha comes after beta.

alpha and beta refer to the same object.

alpha is equivalent to beta but they reference different objects.

3)Which of (a) through (d) is false for the main method?

Each class can have its own main method.

The arguments passed to a main method from a command line are strings.

The main method must be written as the last method in the class.

The main method typically does not return a value

all of the above are true

4)Which of the following statements is true?

Any method that compiles without error is guaranteed to be logically correct.

Java provides a mechanism to distinguish between accessor and mutator methods.

Each class can provide a main to perform testing.

The keyword this is available in all methods, including static methods.

Every class must implement toString and equals.

5)Which of the following is true about reference types?

They are initialized to 0 by default.

The assignment operator (=) can be used to copy the states of two objects.

The equality operator (==) can be used to test if the referenced objects have identical states.

They cannot be passed to methods.

all of the above are false

6)Which of (a) through (d) is false:

A catch block for a standard (unchecked) runtime exception is optional.

An exception is an object.

A throws clause is used to throw an exception.

An exception handling is located inside a catch block.

all of the above are true

7) If two methods in the same class have the same name, which is true:

They must have a different number of lines of code within the method

They must have different return types

They must have different parameter types

The compiler must generate an error message

none of the above

8) Consider short-circuit evaluation for each of the following statements:
boolean a = false;
boolean b = true;
boolean c = false;
boolean d;
In which of the following is d evaluated?

a && d

b && d

c && d

All the operations evaluate d

9) Which of (a) to (c) is false about a static class member?

it must be a method

one member is allocated for each declared class object

the static class member is guaranteed to be private to the class

two of the above are false

all of (a), (b), and (c) are false

11)Which of the following best describes an abstract method?

A method that is constant throughout the inheritance hierarchy.

A method definition that changes in the inheritance hierarchy, but there is a reasonable default implementation in the super class.

No reasonable default implementation can be provided, and the method must be defined in the inheritance hierarchy.

More than one method exists withing the same class that have the same name, but different parameters.

none of the above

12) Which of the following is true?

A variable must be declared immediately before its first use.

An identifier may start with any letter or any digit.

33a is not a valid identifier.

both (a) and (c) are true

all of the above are true

13) In which of the following cases is a class member myVariable invisible to a method myMethod?

myMethod is a method in the same class and myVariable is private

myMethod is a package-friendly method and myVariable is not private

myMethod is a method in another class and myVariable is public

myMethod is a method in another class and myVariable is private

none of the above

a.

myMethod is a method in the same class and myVariable is private

b.

myMethod is a package-friendly method and myVariable is not private

c.

myMethod is a method in another class and myVariable is public

d.

myMethod is a method in another class and myVariable is private

e.

none of the above

Explanation / Answer

1)- myMethod is a method in another class and myVariable is private (as private variables are visible inside the class only.)
2)-alpha is equivalent to beta but they reference different objects.
3- All of the above are true (as each class has its own methods, the arguments passed to main are strings as void main(String args[]),the main method must be written after all the methods,as ainhas a return type void so it does not return anything.)
4-Each class can provide the main to perform testing.
5-b the assignment operator is used to copy the states of two objects.
6-All of the above are true.
7-c-they must have different parameter types (this is known as method overloading)
8-b&&d (as in && operator if first condition is true then only second condition is evaluated as b is true so d will be evaluated.)
9-e-all of a,b,c are false.
11-No reasonable default implementation can be provided,and methods must be defined in inheritance hierarchy.
12- Both a and c are ture.
13- myMethod is a method in another class and myVariable is private