Question-101. What is Local Variable ?

Answer- Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and it will be destroyed when the method has completed.

Question-102. What is Instance Variable? ?

Answer- Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded.

Question-103. What is Class Variable ?

Answer- These are variables declared with in a class, outside any method, with the static keyword.

Question-104. What do you mean by access modifier ?

Answer- Java provides access modifiers to set access levels for classes, variables, methods and constructors. A member has package or default accessibility when no accessibility modifier is specified.

Question-105. What is protected access modifier ?

Answer- Variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members’ class.

Question-106. Why is String class considered immutable ?

Answer- The String class is immutable, so that once it is created a String object cannot be changed. Since String is immutable it can safely be shared between many threads ,which is considered very important for multithreaded programming.

Question-107. Why is StringBuffer called mutable ?

Answer- The String class is considered as immutable, so that once it is created a String object cannot be changed. If there is a necessity to make alot of modifications to Strings of characters then StringBuffer should be used.

Question-108. What is difference between StringBuffer and StringBuilder class? ?

Answer- Use StringBuilder whenever possible because it is faster than StringBuffer. But, if thread safety is necessary then use StringBuffer objects.

Question-109. What is finalize() method ?

Answer- It is possible to define a method that will be called just before an object’s final destruction by the garbage collector. This method is called finalize( ), and it can be used to ensure that an object terminates cleanly.

Question-110. What is an Exception ?

Answer- An exception is a problem that arises during the execution of a program. Exceptions are caught by handlers positioned along the thread’s method invocation stack.