Explore topic-wise InterviewSolutions in .

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.

How can we identify whether a compilation unit is class or interface from a .class file?(a) Java source file header(b) Extension of compilation unit(c) We cannot differentiate between class and interface(d) The class or interface name should be postfixed with unit typeI have been asked this question during an interview for a job.This is a very interesting question from JDK-JRE-JIT-JVM in division Java Environment & OOPS Concepts of Java

Answer» RIGHT choice is (a) Java source file HEADER

Explanation: The Java source file contains a header that DECLARES the type of class or INTERFACE, its visibility with respect to other classes, its name and any SUPERCLASS it may extend, or interface it implements.
2.

What is the extension of compiled java classes?(a) .class(b) .java(c) .txt(d) .jsThis question was addressed to me by my school principal while I was bunking the class.Question is taken from JDK-JRE-JIT-JVM topic in chapter Java Environment & OOPS Concepts of Java

Answer» CORRECT ANSWER is (a) .class

For explanation I would SAY: The COMPILED java files have .class extension.
3.

What is the extension of java code files?(a) .class(b) .java(c) .txt(d) .jsThis question was addressed to me in my homework.Origin of the question is JDK-JRE-JIT-JVM in portion Java Environment & OOPS Concepts of Java

Answer»

The correct OPTION is (b) .JAVA

For explanation: Java FILES have .java EXTENSION.

4.

Which of the below is invalid identifier with the main method?(a) public(b) static(c) private(d) finalThe question was posed to me in unit test.Query is from JDK-JRE-JIT-JVM in division Java Environment & OOPS Concepts of Java

Answer» CORRECT option is (C) PRIVATE

Easy EXPLANATION: main method cannot be private as it is invoked by external method. Other identifier are valid with main method.
5.

Which statement is true about java?(a) Platform independent programming language(b) Platform dependent programming language(c) Code dependent programming language(d) Sequence dependent programming languageThis question was posed to me during an online exam.I would like to ask this question from JDK-JRE-JIT-JVM in division Java Environment & OOPS Concepts of Java

Answer»

Right answer is (a) PLATFORM INDEPENDENT programming language

Easiest EXPLANATION: Java is called ‘Platform Independent Language’ as it primarily WORKS on the principle of ‘compile once, run everywhere’.

6.

Which component is responsible to optimize bytecode to machine code?(a) JVM(b) JDK(c) JIT(d) JREI got this question by my school principal while I was bunking the class.I need to ask this question from JDK-JRE-JIT-JVM in portion Java Environment & OOPS Concepts of Java

Answer»

The correct choice is (C) JIT

The best I can explain: JIT OPTIMIZES bytecode to machine specific language code by COMPILING similar bytecodes at the same time. This reduces OVERALL time taken for compilation of bytecode to machine specific language.

7.

Which component is responsible to run java program?(a) JVM(b) JDK(c) JIT(d) JREThe question was posed to me during a job interview.I would like to ask this question from JDK-JRE-JIT-JVM in section Java Environment & OOPS Concepts of Java

Answer»

Correct choice is (d) JRE

The explanation is: JRE is the IMPLEMENTATION of JVM, it PROVIDES platform to execute JAVA PROGRAMS.

8.

Which component is responsible for converting bytecode into machine specific code?(a) JVM(b) JDK(c) JIT(d) JREThis question was posed to me during a job interview.I want to ask this question from JDK-JRE-JIT-JVM topic in section Java Environment & OOPS Concepts of Java

Answer»

Correct OPTION is (a) JVM

To ELABORATE: JVM is RESPONSIBLE to converting bytecode to the machine specific code. JVM is also platform dependent and provides core java functions LIKE garbage collection, memory management, security ETC.

9.

Which component is used to compile, debug and execute java program?(a) JVM(b) JDK(c) JIT(d) JREThe question was asked in homework.My doubt stems from JDK-JRE-JIT-JVM topic in portion Java Environment & OOPS Concepts of Java

Answer»

Right choice is (b) JDK

Explanation: JDK is a core component of Java Environment and provides all the TOOLS, EXECUTABLES and BINARIES required to compile, DEBUG and execute a Java Program.

10.

What is it called where object has its own lifecycle and child object cannot belong to another parent object?(a) Aggregation(b) Composition(c) Encapsulation(d) AssociationThe question was asked in an online quiz.My question comes from Concepts of OOPs topic in portion Java Environment & OOPS Concepts of Java

Answer»

The CORRECT answer is (a) Aggregation

The best I can explain: Aggregation OCCURS when objects have their own life cycle and CHILD OBJECT can ASSOCIATE with only one parent object.

11.

What is it called where child object gets killed if parent object is killed?(a) Aggregation(b) Composition(c) Encapsulation(d) AssociationThe question was asked during an interview.Origin of the question is Concepts of OOPs topic in portion Java Environment & OOPS Concepts of Java

Answer»

The correct OPTION is (b) Composition

Easiest explanation: Composition occurs when CHILD OBJECT gets killed if parent object gets killed. Aggregation is also known as STRONG Aggregation.

12.

What is it called if an object has its own lifecycle and there is no owner?(a) Aggregation(b) Composition(c) Encapsulation(d) AssociationThe question was posed to me by my school principal while I was bunking the class.This key question is from Concepts of OOPs topic in division Java Environment & OOPS Concepts of Java

Answer» RIGHT option is (d) Association

To ELABORATE: It is a RELATIONSHIP where all objects have their own lifecycle and there is no owner. This OCCURS where MANY to many relationships are available, instead of one to one or one to many.
13.

Which concept of Java is achieved by combining methods and attribute into a class?(a) Encapsulation(b) Inheritance(c) Polymorphism(d) AbstractionThis question was posed to me by my school principal while I was bunking the class.Asked question is from Concepts of OOPs topic in section Java Environment & OOPS Concepts of Java

Answer»

Correct option is (a) Encapsulation

The BEST I can explain: Encapsulation is IMPLEMENTED by combining METHODS and attribute into a CLASS. The class acts like a container of encapsulating properties.

14.

Which concept of Java is a way of converting real world objects in terms of class?(a) Polymorphism(b) Encapsulation(c) Abstraction(d) InheritanceThis question was posed to me in a national level competition.My question is taken from Concepts of OOPs in portion Java Environment & OOPS Concepts of Java

Answer»

Right option is (c) ABSTRACTION

Explanation: Abstraction is the concept of DEFINING real world OBJECTS in TERMS of classes or interfaces.

15.

When Overloading does not occur?(a) More than one method with same name but different method signature and different number or type of parameters(b) More than one method with same name, same signature but different number of signature(c) More than one method with same name, same signature, same number of parameters but different type(d) More than one method with same name, same number of parameters and type but different signatureThis question was addressed to me during an internship interview.Enquiry is from Concepts of OOPs topic in division Java Environment & OOPS Concepts of Java

Answer»

Right option is (d) More than ONE METHOD with same name, same number of parameters and type but DIFFERENT signature

To explain I would say: OVERLOADING occurs when more than one method with same name but different constructor and also when same signature but different number of parameters and/or parameter type.

16.

Which of the following is not OOPS concept in Java?(a) Inheritance(b) Encapsulation(c) Polymorphism(d) CompilationI have been asked this question during an online interview.My query is from Concepts of OOPs topic in portion Java Environment & OOPS Concepts of Java

Answer» RIGHT choice is (d) Compilation

Explanation: There are 4 OOPS CONCEPTS in Java. INHERITANCE, Encapsulation, Polymorphism and Abstraction.
17.

When does method overloading is determined?(a) At run time(b) At compile time(c) At coding time(d) At execution timeI got this question in an online interview.This interesting question is from Concepts of OOPs in section Java Environment & OOPS Concepts of Java

Answer»

Right ANSWER is (b) At compile TIME

For explanation I would say: Overloading is determined at compile time. Hence, it is ALSO KNOWN as compile time POLYMORPHISM.

18.

Which of the following is a type of polymorphism in Java?(a) Compile time polymorphism(b) Execution time polymorphism(c) Multiple polymorphism(d) Multilevel polymorphismI have been asked this question in unit test.The query is from Concepts of OOPs topic in chapter Java Environment & OOPS Concepts of Java

Answer» CORRECT option is (a) Compile TIME polymorphism

Explanation: There are TWO types of polymorphism in JAVA. Compile time polymorphism (overloading) and runtime polymorphism (OVERRIDING).