How does a try statement determine which catch clause should be used to handle an exception?
Correct Answer
When an exception is thrown , the catch block of the try statement are examined in the order in which they appear The first catch block that is capable of handling the exception is executed The remaining catch blocks are ignored
Technology problems
Search Results
1. What is static initializer block? What is its use?
Correct Answer: A static initializer block is a block of code that declares with the static keyword It normally contains the block of code that must execute at the time of class loading The static initializer block will execute only once at the time of loading the class only
2. What is the impact of declaring a method as final?
Correct Answer: Path and Classpath are operating system level environment variales Path is used define where the system can find the executables(exe) files and classpath is used to specify the location class files
4. What are the restrictions when overriding a method ?
Correct Answer: Overridden methods must have the same name, argument list, and return type (ie, they must have the exact signature of the method we are going to override, including return type) The overriding method cannot be less visible than the method it overrides( ie, a public method cannot be override to private) The overriding method may not throw any exceptions that may not be thrown by the overridden method
Correct Answer: Yes, we can In order to compile a java program, we don't require any main method But to execute a java program we must have a main in it (unless it is an applet or servlet) Because main is the starting point of a java program
6. What are the the different ways for creating a thread?
Correct Answer: When creating a thread by extending the Thread class, it is not mandatory to override the run method (If we are not overriding the run method , it is useless), because Thread class have already given a default implementation for run method But if we are implementing Runnable , it is mandatory to override the run method The preferred way to create a thread is by implementing Runnable interface, because it give loose coupling
Correct Answer: A thread is a lightweight subprocess, a smallest unit of processing It is a separate path of execution It shares the memory area of process As shown in the above figure, thread is executed inside the process There is context-switching between the threads There can be multiple processes inside the OS and one process can have multiple threads
9. What do you understand by private, protected and public?
Correct Answer: These are accessibility modifiers Private is the most restrictive, while public is the least restrictive There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package
10. If a method is declared as protected, where may the method be accessed?
Correct Answer: A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared