3
Q:

try { int x = Integer.parseInt("two"); }

Which could be used to create an appropriate catch block?

A) ClassCastException B) IllegalStateException
C) NumberFormatException D) None

Answer:   C) NumberFormatException



Explanation:

C is correct. 'Integer.parseInt' can throw a NumberFormatException, and IllegalArgumentException is its superclass 

Subject: Java
Q:

When will you define a method as static?

Answer When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3563
Q:

What are the restriction imposed on a static method or a static block of code?

Answer A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

5 6345
Q:

I want to print "Hello" even before main() is executed. How will you acheive that?

Answer Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main() method. And it will be executed only once.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

6 7732
Q:

I do not want my class to be inherited by any other class. What should i do?

Answer You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2059
Q:

What is the impact of declaring a method as final?

Answer A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 2841
Q:

What is the purpose of declaring a variable as final?

Answer A final variable's value can't be changed. final variables should be initialized before using them.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2224
Q:

What is the access scope of a protected method?

Answer A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 5362
Q:

Can a class be declared as protected?

Answer A class can't be declared as protected. only methods can be declared as protected.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2108