Quiz2

With respect to access modifier overridden, the right order is:
Private, default, protected, public
Default, private, protected, public
Private, protected, default, public
Public, protected, default, private
Which modifiers on instance variables will announce to the compiler that these variables are not stored as part of its object's persistent state.
Transient
Transient
Native
Volatile
Synchronized
Select an operation which may cause an unchecked exception.
Accessing an element of an array.
Accessing data in a file.
Accessing a remote resource.
Accessing data in a database.
Controlling the state of a running thread.
Select the correct syntax for throwing an exception when declaring a method.
[Modifier] {Return type] Identifier (Parameters) throw TypeOfException
[Modifier] {Return type] Identifier (Parameters) throws TypeOfException
[Modifier] {Return type] Identifier (Parameters) {throw TypeOfException ;
[Modifier] {Return type] Identifier (Parameters) {throws TypeOfException ;
None of the others
Select incorrect Java program entry point declarations. (1) public static void main() (2) public static void main(String [] args) (3) public static void main(String args[]) (4) public static void main(string [] args) (5) public static void main(String args)
1, 4, 5
1, 2, 3
2, 3, 4
3, 4, 5
All of the others.
Select correct statements. (1) A public member of a class can be accessed in all classes. (2) A default member of a class can be accessed in all classes. (3) A protected member of a class can be accessed in the package containing this class. (4) A private member of a class can be accessed in the package containing this class.
1, 3
1, 2
1, 4
1, 2, 3
2, 3, 4
Which of the following Java operations cause compile-time errors? Int m=5, n=7; float x = m; //1 double y= n; //2 m = y; // 3 n = x; // 4
3, 4
1, 3
2, 4
1, 2, 3, 4
If the following code is executed. What is the output? int[] a= {1,2,3,4}; System.out.println(a[6]);
A compile-time exception because they must be put in the try catch block.
ArrayIndexOutOfBoundsException
0
A non-predictable value.
If a Java source code contains an assert as an identifier and it will be compiled with JDK version 1.4 or higher, ….
The option “–source 1.4” must be specified when it is compiled.
The option “–source 1.4 version” must be specified when it is compiled.
The option “–enableassertion” must be specified when it is run.
None of the others.
Which of the following statements are true? 1)An abstract class can not have any final methods. 2)A final class may not have any abstract methods.
Only statement 1.
Only statement 2.
Both statement 1 and 2
None of the others.
When a negative byte is cast to a long, what are the possible values of the result?
Positive value.
Zero.
Negative value.
All of the others.
Suppose a method called finallyTest() method consisting of a try block, followed by a catch block, followed by a finally block. Assuming the JVM doesn’t crash and the code does not execute a System.exit() call, under what circumstances will the finally block not begin to execute?
The try block throws an exception, and the catch block also throws an exception.
The try block throws an exception that is not handled by the catch block.
The try block throws an exception, and the catch block calls finallyTest() in a way that causes another exception to be thrown.
If the JVM doesn't crash and the code does not execute a System.exit() call, the finally block will always execute.
Java compiler allows …….
Implicit widening conversions.
Implicit narrowning conversions
No conversions.
Type casting only.
Errors beyond the control of a program are called .........
Exceptions
Syntax errors
Assertions.
All of the others.
What is NOT a unary operator?
/
--
~
++
What is NOT a comparison operator?
>>
==
!=
Instanceof
A method in a super class is implemented using the default modifier, this method can not be overridden in subclasses using the ….. modifier.
Private
Public
Protected
Default
A …. Method is implemented in a super class can not be overridden in derived classes.
Final
Private
Default
Protected
Public
The try… catch statements must be used to contain statements that ……
May cause checked exceptions.
May cause unchecked exceptions.
May cause compile-time errors.
May cause run-time errors.
Which of the following modifiers is not an access modifier?
Final
Public
Private
Protected
None of the others
Which of the following declarations is not correct?
Private int I;
Public protected String myString;
Public class MyMoney { }
Class ParserNum {}
Which of the following statement is not correct about default access modifier?
To declare a variable that have default access modifier, we use the default keyword. For example: default String myString;
A class’s data and methods may be default, as well as the class itself.
A class that has default access modifier can be accessed by any class in the same package.
A default method may be overridden by any subclass that is in the same package as the super class.
Which of the following statement is NOT correct about protected access modifier?
Only variables and methods may be declared as protected.
Only variables and methods may be declared as protected.
Protected variables of a class can only be accessed by its sub-class in the same package
None of the others.
Int x=2; //1 long z=3; //2 double t=5.4;//3 x=t; //4 z=x; //5 Which statement causes an error?
The statements (4) and (5).
The statement (4) only.
The statement (5) only.
None of the others.
Which of the following declarations is not valid?
Private int[] ar3 = new int[2]{1, 2};
Private int ar2[] = new int[2];
Private int ar1[] = {1,2,3,4};
Private int[] ar = new int[]{1,2,3,4};
Which of the following modifiers can assure that a class is not inherited by other classes?
Final
Abstract
Transient
Volatile
The protected modifier cannot be applied to which of the following declarations?
Static class A { }
Static int x = 10;
Static double = 23.2;
Static string = “123”;
Which of the following modifiers is valid for a constructor?
Private
Static
Synchronized
Final
Which of the following modifiers does not allow a method to be overridden?
Final
Abstract
Public
Protected
Which of the following access modifiers does not allow a class to be accessed outsite its package?
Default
Protected
Public
Final
When handling exceptions, how many catch{} blocks can be used for one try{} block?
1 only.
None of the others
2 only
3 only
Which of the following statements is correct?
For value types, narrowing conversion is not allowed.
For value types, widening conversion is not allowed.
A boolean can be converted to any other type.
None of the others
The default access modifier in Java is …….
None of the others.
Public
Private
Static
Protected
The private and protected modifiers are not applied on .....
Class
Methods of a class
Data members of a class
Contructors of a class.
Study the following Java code: int n= 256; byte x= (byte) n; Suppose that the above code is executed, the value of the variable x is ……
0
25
258
128
None of the others
Which of the following modifiers cannot be applied for a class?
Protected
Public
No modifier (default)
Final
Which of the following modifiers cannot be applied for interface and abstract classes?
Protected
Public
No modifier (default)
Final
Which of the following access modifiers makes a class cannot be inherited?
Final
Static
Private
Protected
Which of the following modifiers makes a variable can be modified asynchronously?
Volatile
Synchronized
Transient
Native
{"name":"Quiz2", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"With respect to access modifier overridden, the right order is:, Which modifiers on instance variables will announce to the compiler that these variables are not stored as part of its object's persistent state., Select an operation which may cause an unchecked exception.","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
Powered by: Quiz Maker