InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 251. |
Can An Interface Extend Another Interface? |
|
Answer» YES an Interface can inherit ANOTHER Interface, for that MATTER an Interface can EXTEND more than one Interface. Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface. |
|
| 252. |
Can An Interface Implement Another Interface? |
|
Answer» Intefaces doesn't provide IMPLEMENTATION hence a INTERFACE cannot IMPLEMENT another interface. Intefaces doesn't provide implementation hence a interface cannot implement another interface. |
|
| 253. |
Can A Method Inside A Interface Be Declared As Final? |
|
Answer» No not POSSIBLE. Doing so will RESULT in compilation error. PUBLIC and ABSTRACT are the only applicable MODIFIERS for method declaration in an interface. No not possible. Doing so will result in compilation error. public and abstract are the only applicable modifiers for method declaration in an interface. |
|
| 254. |
Class C Implements Interface I Containing Method M1 And M2 Declarations. Class C Has Provided Implementation For Method M2. Can I Create An Object Of Class C? |
|
Answer» No not possible. Class C should provide implementation for all the methods in the Interface I. SINCE Class C didn't provide implementation for M1 method, it has to be declared as ABSTRACT. Abstract classes can't be INSTANTIATED. No not possible. Class C should provide implementation for all the methods in the Interface I. Since Class C didn't provide implementation for m1 method, it has to be declared as abstract. Abstract classes can't be instantiated. |
|
| 255. |
Can A Abstract Class Be Defined Without Any Abstract Methods? |
|
Answer» YES it's possible. This is basically to AVOID INSTANCE creation of the class. Yes it's possible. This is basically to avoid instance creation of the class. |
|
| 256. |
Can You Create An Object Of An Abstract Class? |
|
Answer» Not POSSIBLE. ABSTRACT CLASSES can't be INSTANTIATED. Not possible. Abstract classes can't be instantiated. |
|
| 257. |
What Is Use Of A Abstract Variable? |
|
Answer» Variables can't be DECLARED as ABSTRACT. only CLASSES and methods can be declared as abstract. Variables can't be declared as abstract. only classes and methods can be declared as abstract. |
|
| 258. |
Can A Abstract Class Be Declared Final? |
|
Answer» Not POSSIBLE. An ABSTRACT class without being inherited is of no USE and hence will RESULT in compile time error. Not possible. An abstract class without being inherited is of no use and hence will result in compile time error. |
|
| 259. |
What Is An Abstract Class And What Is It's Purpose? |
|
Answer» A CLASS which doesn't provide complete IMPLEMENTATION is DEFINED as an abstract class. Abstract classes ENFORCE abstraction. A Class which doesn't provide complete implementation is defined as an abstract class. Abstract classes enforce abstraction. |
|
| 260. |
Can We Declare A Static Variable Inside A Method? |
|
Answer» STATIC variables are class LEVEL variables and they can't be declared INSIDE a method. If declared, the class will not compile. Static variables are class level variables and they can't be declared inside a method. If declared, the class will not compile. |
|
| 261. |
What Is The Importance Of Static Variable? |
|
Answer» static variables are CLASS LEVEL variables where all OBJECTS of the class refer to the same variable. If ONE object changes the value then the CHANGE gets reflected in all the objects. static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects. |
|
| 262. |
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. 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. |
|
| 263. |
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. A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance. |
|
| 264. |
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. 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. |
|
| 265. |
Can A Class Be Declared As Static? |
|
Answer» No a CLASS cannot be DEFINED as static. Only a method,a VARIABLE or a BLOCK of code can be declared as static. No a class cannot be defined as static. Only a method,a variable or a block of code can be declared as static. |
|
| 266. |
How Is Final Different From Finally And Finalize? |
|
Answer» final is a modifier which can be applied to a class or a METHOD or a variable. final class can't be inherited, final method can't be overridden and final variable can't be changed. finally is an EXCEPTION handling CODE section which gets executed whether an exception is raised or not by the try block code SEGMENT. finalize() is a method of Object class which will be executed by the JVM just before GARBAGE collecting object to give a final chance for resource releasing activity. final is a modifier which can be applied to a class or a method or a variable. final class can't be inherited, final method can't be overridden and final variable can't be changed. finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment. finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity. |
|
| 267. |
I Don't 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. 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. |
|
| 268. |
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. A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation. |
|
| 269. |
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. A final variable's value can't be changed. final variables should be initialized before using them. |
|
| 270. |
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. A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package. |
|
| 271. |
Can A Class Be Declared As Protected? |
|
Answer» A CLASS can't be DECLARED as PROTECTED. only METHODS can be declared as protected. A class can't be declared as protected. only methods can be declared as protected. |
|
| 272. |
Can A Class Declared As Private Be Accessed Outside It's Package? |
|
Answer» Not POSSIBLE. Not possible. |
|
| 273. |
Which Package Is Imported By Default? |
|
Answer» java.lang PACKAGE is imported by DEFAULT even WITHOUT a package declaration. java.lang package is imported by default even without a package declaration. |
|
| 274. |
Can A Source File Contain More Than One Class Declaration? |
|
Answer» YES a single source FILE can contain any number of Class declarations but only one of the class can be DECLARED as public. Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public. |
|
| 275. |
Does The Order Of Public And Static Declaration Matter In Main Method? |
|
Answer» No it doesn't MATTER but VOID should ALWAYS COME before MAIN(). No it doesn't matter but void should always come before main(). |
|
| 276. |
Can A Main Method Be Declared Final? |
|
Answer» YES. Any INHERITING class will not be able to have it's own default MAIN method. Yes. Any inheriting class will not be able to have it's own default main method. |
|
| 277. |
Can A Main Method Be Overloaded? |
|
Answer» Yes. You can have any NUMBER of main methods with different METHOD SIGNATURE and implementation in the CLASS. Yes. You can have any number of main methods with different method signature and implementation in the class. |
|
| 278. |
What Is The Arguement Of Main Method? |
|
Answer» main method ACCEPTS an ARRAY of STRING object as ARGUEMENT. main method accepts an array of String object as arguement. |
|
| 279. |
Why Is The Main Method Declared Static? |
|
Answer» main method is CALLED by the JVM even before the instantiation of the class HENCE it is DECLARED as static. main method is called by the JVM even before the instantiation of the class hence it is declared as static. |
|
| 280. |
What Is The Return Type Of The Main Method? |
|
Answer» Main method doesn't RETURN ANYTHING hence declared VOID. Main method doesn't return anything hence declared void. |
|
| 281. |
Should A Main Method Be Compulsorily Declared In All Java Classes? |
|
Answer» No not REQUIRED. main method should be DEFINED only if the SOURCE class is a java APPLICATION. No not required. main method should be defined only if the source class is a java application. |
|
| 282. |
How To Define A Constant Variable In Java? |
|
Answer» The variable should be declared as static and final. So only one COPY of the variable exists for all instances of the class and the value can't be CHANGED ALSO. static final int PI = 2.14; is an EXAMPLE for constant. The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also. static final int PI = 2.14; is an example for constant. |
|
| 283. |
What Are Local Variables? |
|
Answer» Local varaiables are those which are declared within a BLOCK of CODE like METHODS. Local VARIABLES should be INITIALISED before accessing them. Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them. |
|
| 284. |
What Is Difference Between Path And Classpath? |
|
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. 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. |
|
| 285. |
Are Arrays Primitive Data Types? |
|
Answer» In Java, Arrays are objects. |
|
| 286. |
Is Java A Pure Object Oriented Language? |
|
Answer» Java uses primitive data TYPES and hence is not a PURE object oriented LANGUAGE. Java uses primitive data types and hence is not a pure object oriented language. |
|
| 287. |
Does Java Support Multiple Inheritance? |
|
Answer» JAVA doesn't SUPPORT MULTIPLE INHERITANCE. Java doesn't support multiple inheritance. |
|
| 288. |
What Is The Base Class Of All Classes? |
|
Answer» java.lang.Object java.lang.Object |
|
| 289. |
What Is The Difference Between A Jdk And A Jvm? |
|
Answer» JDK is Java Development Kit which is for development PURPOSE and it includes execution environment also. But JVM is purely a run time environment and hence you will not be ABLE to compile your source files USING a JVM. JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM. |
|
| 290. |
What Is A Jvm? |
|
Answer» JVM is JAVA Virtual Machine which is a RUN TIME environment for the compiled java class FILES. JVM is Java Virtual Machine which is a run time environment for the compiled java class files. |
|
| 291. |
Are Jvm's Platform Independent? |
|
Answer» JVM's are not platform independent. JVM's are platform SPECIFIC RUN time IMPLEMENTATION provided by the vendor. JVM's are not platform independent. JVM's are platform specific run time implementation provided by the vendor. |
|
| 292. |
What Is The Most Important Feature Of Java? |
|
Answer» JAVA is a PLATFORM INDEPENDENT LANGUAGE. Java is a platform independent language. |
|