Java Declaration Initialization and Access Control Quiz 6

Time limit: 0

Quiz-summary

0 of 10 questions completed

Questions:

1

2

3

4

5

6

7

8

9

10

Information

Java declaration, initialization and access control quiz 5 contains 10 single questions. Declaration, initialization and access control quiz questions are designed in such a way that it will help you understand how to declare and initialize variables in Java as well as how to properly define access control for class, member variables and methods. At the end of the quiz, result will be displayed along with your score and quiz answers.

There is no time limit to complete the quiz. Click Start Quiz button to start the Java Declaration, Initialization and Access Control quiz online.

You have already completed the quiz before. Hence you can not start it again.

Option 2 is the correct choice. If the string argument passed in Boolean(String s) constructor is not null and is equal to true ignoring case, then Boolean object representing true is created. For every other string value, Boolean object representing false will be created.

The code creates a Boolean object by passing string “TestClass” in the constructor, which is not null and does not equal to true so Boolean object representing false will be created. The code then prints the value of it which is false.

Incorrect answer.

Option 2 is the correct choice. If the string argument passed in Boolean(String s) constructor is not null and is equal to true ignoring case, then Boolean object representing true is created. For every other string value, Boolean object representing false will be created.

The code creates a Boolean object by passing string “TestClass” in the constructor, which is not null and does not equal to true so Boolean object representing false will be created. The code then prints the value of it which is false.

Option 1 is the correct choice. The code will output BlueBlue when compiled and run.

Method parameters are passed by value in Java. When it comes to an object as a method parameter, Java copies the object reference. It means that when you change the object properties using objects methods in the method which is called, the original object changes as well.

Remember, only reference is being copied not the object itself.

Incorrect answer.

Option 1 is the correct choice. The code will output BlueBlue when compiled and run.

Method parameters are passed by value in Java. When it comes to an object as a method parameter, Java copies the object reference. It means that when you change the object properties using objects methods in the method which is called, the original object changes as well.

Option 2 is the correct choice. The code will output BlueRed when compiled and run.

Method parameters are passed by value in Java. When it comes to an object as method parameter, Java copies the object reference. That means that the copy of the reference is still pointing to the original object so any change you made using object methods still reflects to the caller method when you access the object using original reference.

However, if you change the copied reference to point to new a object like we did here and change its properties, the original object remains unchanged.

Incorrect answer.

Option 2 is the correct choice. The code will output BlueRed when compiled and run.

Method parameters are passed by value in Java. When it comes to an object as method parameter, Java copies the object reference. That means that the copy of the reference is still pointing to the original object so any change you made using object methods still reflects to the caller method when you access the object using original reference.

However, if you change the copied reference to point to new a object like we did here and change its properties, the original object remains unchanged.

Question 7 of 10

7. Question

A final method cannot be overloaded.

True

False

Correct answer.

False is the correct choice. A final method cannot be overridden in the subclass. However, it can be overloaded.

Incorrect answer.

False is the correct choice. A final method cannot be overridden in the subclass. However, it can be overloaded.

Question 8 of 10

8. Question

Yes is the correct choice. It is mandatory to specify the first dimension of multidimensional array. However, other dimension can be left blank. It is also valid to have different lengths for different dimensions.

Incorrect answer.

Yes is the correct choice. It is mandatory to specify the first dimension of multidimensional array. However, other dimension can be left blank. It is also valid to have different lengths for different dimensions.

Question 9 of 10

9. Question

A final class can be abstract.

True

False

Correct answer.

False is the correct choice. A class can either be final or an abstract, not both.

Incorrect answer.

False is the correct choice. A class can either be final or an abstract, not both.

Option 4 is the correct choice. 10 is considered as int literal and thus can be assigned to float variable. However, 10.2 is a double literal which cannot be assigned to float and will result in compilation error.

float f2 = 10.2f will be correct way to create a float variable.

Incorrect answer.

Option 4 is the correct choice. 10 is considered as int literal and thus can be assigned to float variable. However, 10.2 is a double literal which cannot be assigned to float and will result in compilation error.