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.
| 1. |
Which of these is not a correct statement?(a) A recursive method must have a base case(b) Recursion always uses stack(c) Recursive methods are faster that programmers written loop to call the function repeatedly using a stack(d) Recursion is managed by Java Runtime environmentThis question was posed to me during an interview for a job.My doubt stems from Recursion topic in section Classes and Methods of Java |
|
Answer» Right ANSWER is (d) Recursion is MANAGED by JAVA Runtime environment |
|
| 2. |
What is Recursion in Java?(a) Recursion is a class(b) Recursion is a process of defining a method that calls other methods repeatedly(c) Recursion is a process of defining a method that calls itself repeatedly(d) Recursion is a process of defining a method that calls other methods which in turn call again this methodI have been asked this question in final exam.The origin of the question is Recursion topic in chapter Classes and Methods of Java |
|
Answer» CORRECT answer is (b) Recursion is a process of defining a METHOD that calls other METHODS repeatedly The explanation is: Recursion is the process of defining something in terms of itself. It allows US to define a method that calls itself. |
|
| 3. |
Which of these will happen if recursive method does not have a base case?(a) An infinite loop occurs(b) System stops the program after some time(c) After 1000000 calls it will be automatically stopped(d) None of the mentionedThe question was asked in a national level competition.My question is based upon Recursion topic in portion Classes and Methods of Java |
|
Answer» CORRECT ANSWER is (a) An INFINITE loop occurs Easiest explanation: If a RECURSIVE method does not have a base case then an infinite loop occurs which RESULTS in Stack Overflow. |
|
| 4. |
Which of these data types is used by operating system to manage the Recursion in Java?(a) Array(b) Stack(c) Queue(d) TreeThis question was addressed to me during a job interview.I'm obligated to ask this question of Recursion in chapter Classes and Methods of Java |
|
Answer» Correct answer is (b) STACK |
|
| 5. |
What is the use of @syntax?(a) Allows multiple parameters to be passed(b) Allows one to put all your options into a file and pass this file as a parameter(c) Allows one to pass only one parameter(d) Allows one to pass one file containing only one parameterThis question was addressed to me by my school teacher while I was bunking the class.My doubt stems from Command Line Arguments topic in portion Classes and Methods of Java |
|
Answer» The CORRECT ANSWER is (b) Allows one to put all your OPTIONS into a file and pass this file as a parameter |
|
| 6. |
Which annotation is used to represent command line input and assigned to correct data type?(a) @Input(b) @Variable(c) @Command Line(d) @ParameterI have been asked this question during an interview for a job.My question is taken from Command Line Arguments in section Classes and Methods of Java |
|
Answer» The CORRECT option is (d) @Parameter |
|
| 7. |
Which class allows parsing of command line arguments?(a) Args(b) JCommander(c) Command Line(d) InputI have been asked this question at a job interview.This intriguing question comes from Command Line Arguments topic in portion Classes and Methods of Java |
|
Answer» Correct ANSWER is (b) JCommander |
|
| 8. |
How many arguments can be passed to main()?(a) Infinite(b) Only 1(c) System Dependent(d) None of the mentionedI had been asked this question in homework.This interesting question is from Command Line Arguments topic in portion Classes and Methods of Java |
|
Answer» CORRECT ANSWER is (a) Infinite The EXPLANATION is: NONE. |
|
| 9. |
How do we pass command line argument in Eclipse?(a) Arguments tab(b) Variable tab(c) Cannot pass command line argument in eclipse(d) Environment variable tabI had been asked this question in an interview for internship.This question is from Command Line Arguments topic in section Classes and Methods of Java |
|
Answer» The CORRECT ANSWER is (a) Arguments TAB |
|
| 10. |
Which of these data types is used to store command line arguments?(a) Array(b) Stack(c) String(d) IntegerI had been asked this question in an online quiz.Origin of the question is Command Line Arguments topic in section Classes and Methods of Java |
|
Answer» The CORRECT OPTION is (C) String |
|
| 11. |
Which of these data type can be used for a method having a return statement in it?(a) void(b) int(c) float(d) both int and floatThe question was asked in homework.Question is taken from Methods Taking Parameters in portion Classes and Methods of Java |
|
Answer» RIGHT option is (d) both INT and float To EXPLAIN I WOULD say: None. |
|
| 12. |
What is the process of defining more than one method in a class differentiated by parameters?(a) Function overriding(b) Function overloading(c) Function doubling(d) None of the mentionedI have been asked this question during an interview for a job.The query is from Methods Taking Parameters topic in section Classes and Methods of Java |
|
Answer» RIGHT answer is (b) Function overloading To elaborate: Function overloading is a process of defining more than one METHOD in a class with same NAME differentiated by function signature i:E return type or parameters type and number. Example –int volume(int length, int WIDTH) & int volume(int length , int width , int height) can be used to calculate volume. |
|
| 13. |
Which of these can be used to differentiate two or more methods having the same name?(a) Parameters data type(b) Number of parameters(c) Return type of method(d) All of the mentionedThis question was posed to me during an interview.I need to ask this question from Methods Taking Parameters topic in portion Classes and Methods of Java |
|
Answer» RIGHT OPTION is (d) All of the mentioned The BEST EXPLANATION: NONE. |
|
| 14. |
Which of this method is given parameter via command line arguments?(a) main()(b) recursive() method(c) Any method(d) System defined methodsThe question was asked in an interview.My enquiry is from Command Line Arguments in chapter Classes and Methods of Java |
|
Answer» Correct option is (a) main() |
|
| 15. |
What is the process of defining more than one method in a class differentiated by parameters?(a) Function overriding(b) Function overloading(c) Function doubling(d) None of the mentionedThe question was posed to me in unit test.I'd like to ask this question from Methods Taking Parameters in division Classes and Methods of Java |
| Answer» | |
| 16. |
Which of these method of String class can be used to test to strings for equality?(a) isequal()(b) isequals()(c) equal()(d) equals()I have been asked this question in an online interview.My enquiry is from String Class topic in chapter Classes and Methods of Java |
|
Answer» CORRECT CHOICE is (d) EQUALS() EASY EXPLANATION: None. |
|
| 17. |
Which of these method of String class is used to obtain character at specified index?(a) char()(b) Charat()(c) charat()(d) charAt()I have been asked this question during an internship interview.I'm obligated to ask this question of String Class in division Classes and Methods of Java |
|
Answer» CORRECT CHOICE is (d) charAt() BEST EXPLANATION: NONE. |
|
| 18. |
Which of these keywords is used to refer to member of base class from a subclass?(a) upper(b) super(c) this(d) none of the mentionedThis question was addressed to me in an interview for job.My question is taken from String Class in section Classes and Methods of Java |
|
Answer» The correct choice is (b) SUPER |
|
| 19. |
Which of these is the method which is executed first before execution of any other thing takes place in a program?(a) main method(b) finalize method(c) static method(d) private methodThis question was addressed to me by my college professor while I was bunking the class.Origin of the question is Methods Taking Parameters topic in portion Classes and Methods of Java |
|
Answer» Right answer is (c) STATIC method |
|
| 20. |
String in Java is a?(a) class(b) object(c) variable(d) character arrayI got this question during an interview for a job.Asked question is from String Class in division Classes and Methods of Java |
|
Answer» CORRECT ANSWER is (a) class The EXPLANATION: NONE. |
|
| 21. |
Which of these methods must be made static?(a) main()(b) delete()(c) run()(d) finalize()The question was posed to me during an internship interview.My question comes from Arrays Revisited & Keyword static in portion Classes and Methods of Java |
|
Answer» Correct option is (a) MAIN() |
|
| 22. |
Which of these keywords is used to prevent content of a variable from being modified?(a) final(b) last(c) constant(d) staticThe question was asked in examination.My question is based upon Arrays Revisited & Keyword static in division Classes and Methods of Java |
|
Answer» Correct CHOICE is (a) final |
|
| 23. |
Which of these cannot be declared static?(a) class(b) object(c) variable(d) methodThis question was addressed to me during an interview.The query is from Arrays Revisited & Keyword static in portion Classes and Methods of Java |
|
Answer» RIGHT choice is (b) object Easy explanation: static STATEMENTS are run as soon as class containing then is LOADED, PRIOR to any object declaration. |
|
| 24. |
Which of the following statements are incorrect?(a) Variables declared as final occupy memory(b) final variable must be initialized at the time of declaration(c) Arrays in java are implemented as an object(d) All arrays contain an attribute-length which contains the number of elements stored in the arrayThe question was asked in an interview for job.My question is taken from Arrays Revisited & Keyword static topic in section Classes and Methods of Java |
|
Answer» The correct CHOICE is (a) VARIABLES declared as FINAL occupy memory |
|
| 25. |
Which of the following statements are incorrect?(a) static methods can call other static methods only(b) static methods must only access static data(c) static methods can not refer to this or super in any way(d) when object of class is declared, each object contains its own copy of static variablesThis question was addressed to me in my homework.This intriguing question originated from Arrays Revisited & Keyword static in portion Classes and Methods of Java |
|
Answer» Right choice is (d) when object of CLASS is declared, each object CONTAINS its own copy of static variables |
|
| 26. |
What is true of final class?(a) Final class cause compilation failure(b) Final class cannot be instantiated(c) Final class cause runtime failure(d) Final class cannot be inheritedThe question was posed to me in an online quiz.This question is from Access Control in chapter Classes and Methods of Java |
|
Answer» RIGHT answer is (d) FINAL CLASS cannot be INHERITED For explanation: Final class cannot be inherited. This HELPS when we do not want classes to provide extension to these classes. |
|
| 27. |
Arrays in Java are implemented as?(a) class(b) object(c) variable(d) none of the mentionedThe question was posed to me during an interview.This is a very interesting question from Arrays Revisited & Keyword static in portion Classes and Methods of Java |
|
Answer» The CORRECT OPTION is (B) object |
|
| 28. |
How many copies of static and class variables are created when 10 objects are created of a class?(a) 1, 10(b) 10, 10(c) 10, 1(d) 1, 1This question was addressed to me by my school principal while I was bunking the class.My question is based upon Access Control topic in section Classes and Methods of Java |
|
Answer» Correct option is (a) 1, 10 |
|
| 29. |
Which is the modifier when there is none mentioned explicitly?(a) protected(b) private(c) public(d) defaultThe question was posed to me by my college director while I was bunking the class.Question is taken from Access Control in division Classes and Methods of Java |
|
Answer» Right option is (d) default |
|
| 30. |
Can a class be declared with a protected modifier.(a) True(b) FalseThis question was posed to me by my college professor while I was bunking the class.I need to ask this question from Access Control in section Classes and Methods of Java |
|
Answer» The CORRECT choice is (b) False |
|
| 31. |
All the variables of interface should be?(a) default and final(b) default and static(c) public, static and final(d) protect, static and finalI had been asked this question in an internship interview.My query is from Access Control topic in chapter Classes and Methods of Java |
|
Answer» Right option is (c) public, STATIC and FINAL |
|
| 32. |
What happens if constructor of class A is made private?(a) Any class can instantiate objects of class A(b) Objects of class A can be instantiated only within the class where it is declared(c) Inherited class can instantiate objects of class A(d) classes within the same package as class A can instantiate objects of class AThis question was posed to me in homework.I'd like to ask this question from Access Control topic in section Classes and Methods of Java |
|
Answer» Right CHOICE is (b) Objects of CLASS A can be INSTANTIATED only WITHIN the class where it is declared |
|
| 33. |
How can a protected modifier be accessed?(a) accessible only within the class(b) accessible only within package(c) accessible within package and outside the package but through inheritance only(d) accessible by allThis question was addressed to me in a job interview.I would like to ask this question from Access Control in section Classes and Methods of Java |
|
Answer» The correct choice is (c) ACCESSIBLE within package and outside the package but through INHERITANCE only |
|
| 34. |
All the variables of class should be ideally declared as?(a) private(b) public(c) protected(d) defaultI had been asked this question by my school teacher while I was bunking the class.My question is from Access Control in division Classes and Methods of Java |
|
Answer» Correct ANSWER is (a) PRIVATE |
|
| 35. |
Which of the following modifier means a particular variable cannot be accessed within the package?(a) private(b) public(c) protected(d) defaultI had been asked this question in unit test.I'm obligated to ask this question of Access Control topic in chapter Classes and Methods of Java |
|
Answer» The correct CHOICE is (a) PRIVATE |
|
| 36. |
Which of the following statements are incorrect?(a) public members of class can be accessed by any code in the program(b) private members of class can only be accessed by other members of the class(c) private members of class can be inherited by a subclass, and become protected members in subclass(d) protected members of a class can be inherited by a subclass, and become private members of the subclassThe question was posed to me in unit test.I'm obligated to ask this question of Access Control topic in section Classes and Methods of Java |
|
Answer» CORRECT answer is (c) PRIVATE MEMBERS of class can be inherited by a subclass, and become protected members in subclass Easy explanation: private members of a class can not be inherited by a subclass. |
|
| 37. |
Which one of the following is not an access modifier?(a) Public(b) Private(c) Protected(d) VoidThe question was posed to me in an international level competition.Enquiry is from Access Control in chapter Classes and Methods of Java |
|
Answer» RIGHT ANSWER is (d) Void The explanation is: Public, PRIVATE, protected and DEFAULT are the access MODIFIERS. |
|
| 38. |
What is the process by which we can control what parts of a program can access the members of a class?(a) Polymorphism(b) Abstraction(c) Encapsulation(d) RecursionI got this question by my school principal while I was bunking the class.I'd like to ask this question from Access Control topic in portion Classes and Methods of Java |
|
Answer» CORRECT ANSWER is (C) Encapsulation For EXPLANATION: NONE. |
|
| 39. |
Which of these is used as a default for a member of a class if no access specifier is used for it?(a) private(b) public(c) public, within its own package(d) protectedThe question was posed to me in an interview.My question is from Access Control topic in division Classes and Methods of Java |
|
Answer» Correct OPTION is (a) private |
|
| 40. |
Which of these is used to access a member of class before object of that class is created?(a) public(b) private(c) static(d) protectedI got this question during an interview.The origin of the question is Access Control in portion Classes and Methods of Java |
|
Answer» The CORRECT CHOICE is (C) static |
|
| 41. |
Which of these is correct about passing an argument by call-by-value process?(a) Copy of argument is made into the formal parameter of the subroutine(b) Reference to original argument is passed to formal parameter of the subroutine(c) Copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument(d) Reference to original argument is passed to formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argumentThis question was addressed to me in a job interview.Origin of the question is Overloading Methods & Argument Passing in division Classes and Methods of Java |
|
Answer» Correct OPTION is (a) Copy of argument is MADE into the formal PARAMETER of the subroutine |
|
| 42. |
Which of these access specifiers must be used for main() method?(a) private(b) public(c) protected(d) none of the mentionedI had been asked this question at a job interview.I want to ask this question from Access Control topic in division Classes and Methods of Java |
|
Answer» The correct CHOICE is (b) public |
|
| 43. |
Which of these can be overloaded?(a) Methods(b) Constructors(c) All of the mentioned(d) None of the mentionedThis question was addressed to me by my college professor while I was bunking the class.My question comes from Overloading Methods & Argument Passing in portion Classes and Methods of Java |
|
Answer» RIGHT CHOICE is (C) All of the mentioned Explanation: NONE. |
|
| 44. |
What is the process of defining two or more methods within same class that have same name but different parameters declaration?(a) method overloading(b) method overriding(c) method hiding(d) none of the mentionedI had been asked this question in an internship interview.The question is from Overloading Methods & Argument Passing in chapter Classes and Methods of Java |
|
Answer» The correct choice is (a) METHOD overloading |
|
| 45. |
Which of the below is not a memory leak solution?(a) Code changes(b) JVM parameter tuning(c) Process restart(d) GC parameter tuningThe question was posed to me during an online exam.This is a very interesting question from Heap and Garbage Collection in chapter Classes and Methods of Java |
|
Answer» CORRECT choice is (c) Process RESTART The explanation: Process restart is not a PERMANENT fix to MEMORY LEAK problem. The problem will resurge again. |
|
| 46. |
Which of the below is not a Java Profiler?(a) JVM(b) JConsole(c) JProfiler(d) Eclipse ProfilerThis question was addressed to me during an interview.The above asked question is from Heap and Garbage Collection in division Classes and Methods of Java |
|
Answer» Right answer is (a) JVM |
|
| 47. |
What happens to the thread when garbage collection kicks off?(a) The thread continues its operation(b) Garbage collection cannot happen until the thread is running(c) The thread is paused while garbage collection runs(d) The thread and garbage collection do not interfere with each otherThe question was asked in homework.I need to ask this question from Heap and Garbage Collection topic in chapter Classes and Methods of Java |
|
Answer» Right option is (C) The THREAD is PAUSED while garbage COLLECTION runs |
|
| 48. |
How to get prints of shared object memory maps or heap memory maps for a given process?(a) jmap(b) memorymap(c) memorypath(d) jvmmapI have been asked this question in unit test.Origin of the question is Heap and Garbage Collection in division Classes and Methods of Java |
|
Answer» RIGHT CHOICE is (a) JMAP Explanation: We can use jmap as jmap -J-d64 -heap PID. |
|
| 49. |
Which exception is thrown when java is out of memory?(a) MemoryFullException(b) MemoryOutOfBoundsException(c) OutOfMemoryError(d) MemoryErrorThe question was asked by my college director while I was bunking the class.My question is taken from Heap and Garbage Collection topic in section Classes and Methods of Java |
|
Answer» Right option is (C) OutOfMemoryError |
|
| 50. |
What is -Xms and -Xmx while starting jvm?(a) Initial; Maximum memory(b) Maximum; Initial memory(c) Maximum memory(d) Initial memoryThis question was addressed to me in my homework.Question is from Heap and Garbage Collection topic in division Classes and Methods of Java |
|
Answer» CORRECT OPTION is (a) INITIAL; Maximum memory The best explanation: JVM will be started with Xms amount of memory and will be able to USE a maximum of Xmx amount of memory. java -Xmx2048m -Xms256m. |
|