1.
JAVA was first called as?
Correct Answer
B. Oak
Explanation
JAVA was originally developed by James Gosling and his team at Sun Microsystems in the early 1990s. They initially named the language "Oak" after an oak tree that stood outside Gosling's office. However, due to trademark issues, they had to change the name to "JAVA" later on. Therefore, the correct answer is Oak.
2.
Which component is responsible for converting bytecode into machine specific code?
Correct Answer
A. JVM
Explanation
JVM (Java Virtual Machine) is responsible for converting bytecode into machine specific code. It is an essential component of the Java platform that executes Java programs by interpreting the bytecode and translating it into machine code that can be understood by the underlying operating system. JVM acts as an intermediary between the Java program and the operating system, ensuring platform independence by providing a layer of abstraction. It also provides various services such as memory management, garbage collection, and exception handling.
3.
Which statement is true about java?
Correct Answer
A. Platform independent programming language
Explanation
Java is a platform-independent programming language because it can run on any operating system or platform that has a Java Virtual Machine (JVM) installed. This means that Java code written on one platform can be executed on any other platform without the need for any modifications. The JVM acts as an intermediary between the Java code and the underlying operating system, allowing Java programs to be executed on different platforms without any compatibility issues. This platform independence is one of the key features of Java, making it a popular choice for developing cross-platform applications.
4.
Which of the below is invalid identifier with the main method?
Correct Answer
D. Final
Explanation
The keyword "final" is an invalid identifier with the main method because it is a reserved keyword in Java and cannot be used as an identifier. Reserved keywords have predefined meanings in the language and cannot be used for variable names, method names, or class names. The main method is a special method in Java that serves as the entry point for a program, and it requires a valid identifier as its name.
5.
What is the extension of java code files?
Correct Answer
B. .java
Explanation
The extension of java code files is .java. This is the standard file extension used for Java programming language source code files. It helps to identify and distinguish Java files from other types of files.
6.
Java is Architecture Neutral.
Correct Answer
A. True
Explanation
Java is considered architecture neutral because it can run on any platform or operating system without needing to be recompiled. This is achieved through the use of the Java Virtual Machine (JVM), which interprets Java bytecode and translates it into machine code that is specific to the underlying hardware. This allows Java programs to be written once and run anywhere, making it a highly portable and versatile programming language.
7.
Decrement operator, −−, decreases the value of variable by what number?
Correct Answer
A. 1
Explanation
The decrement operator, --, decreases the value of a variable by 1.
8.
Which of the following is not OOPS concept in Java?
Correct Answer
D. Compilation
Explanation
Compilation is not an OOPS concept in Java because it is a process of translating high-level programming language code into machine-readable code. OOPS concepts in Java are Inheritance, Encapsulation, and Polymorphism, which are fundamental principles that allow for modular and reusable code. Compilation is a step that occurs during the execution of the OOPS concepts but is not a concept itself.
9.
Which of the following is a method having same name as that of its class?
Correct Answer
D. Constructor
Explanation
A constructor is a special method in a class that has the same name as the class itself. It is used to initialize the objects of that class and is automatically called when an object is created. Therefore, the correct answer is constructor.
10.
What is the return type of Constructors?
Correct Answer
D. None of the mentioned
Explanation
Constructors do not have a return type. They are special methods that are used to initialize objects of a class. Their purpose is to allocate memory for the object and initialize its member variables. Since constructors do not return any value, the return type is "void". Therefore, the correct answer is "none of the mentioned".
11.
Which function is used to perform some action when the object is to be destroyed?
Correct Answer
A. Finalize()
Explanation
The finalize() function is used to perform some action when an object is about to be destroyed. This function is called by the garbage collector before reclaiming the memory occupied by the object. It allows the programmer to clean up any resources or perform any necessary operations before the object is no longer accessible. The delete() function is used to deallocate memory for dynamically allocated objects, but it does not specifically handle the destruction of an object. The main() function is the entry point of a program and is not directly related to the destruction of objects. Therefore, the correct answer is finalize().
12.
What is the output of this program?
-
class box
-
{
-
int width;
-
int height;
-
int length;
-
int volume;
-
box()
-
{
-
width = 5;
-
height = 5;
-
length = 6;
-
}
-
void volume()
-
{
-
volume = width*height*length;
-
}
-
}
-
class constructor_output
-
{
-
public static void main(String args[])
-
{
-
box obj = new box();
-
obj.volume();
-
System.out.println(obj.volume);
-
}
-
}
Correct Answer
C. 150
Explanation
The output of this program is 150. This is because the program defines a class called "box" with instance variables width, height, length, and volume. It also has a default constructor that initializes the width, height, and length variables to specific values. The class also has a method called "volume" which calculates the volume of the box by multiplying the width, height, and length. In the main method of the "constructor_output" class, an object of the "box" class is created and its volume is calculated using the volume method. Finally, the volume of the box is printed, which is 150 in this case.
13.
Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed?
Correct Answer
D. None of the mentioned
Explanation
The correct answer is "none of the mentioned" because Java does not provide an explicit operator to free the memory of an object. Instead, Java relies on automatic garbage collection, where the Java runtime environment automatically identifies and frees the memory of objects that are no longer referenced by the program.
14.
Which of these keywords is used to make a class?
Correct Answer
A. Class
Explanation
The keyword "class" is used to make a class in programming. A class is a blueprint for creating objects, and it defines the properties and behaviors that the objects will have. By using the "class" keyword, we can define a new class and then create instances of that class. The other keywords mentioned, "struct" and "int", are not used to make a class. "struct" is used to define a structure, which is similar to a class but with different default access modifiers. "int" is a data type used to represent integers. Therefore, the correct keyword to make a class is "class".
15.
Which of these operators is used to allocate memory for an object?
Correct Answer
C. New
Explanation
The "new" operator is used to allocate memory for an object. It is a keyword in C++ that dynamically allocates memory for a single object and returns a pointer to that object. This allows for dynamic memory allocation during runtime, which is useful when the size or number of objects needed is not known at compile time. The "malloc" and "alloc" options are not correct as they are not valid operators in C++ for memory allocation. The "give" option is not a valid operator at all.
16.
What is the output of this program?
-
class box
-
{
-
int width;
-
int height;
-
int length;
-
}
-
class mainclass
-
{
-
public static void main(String args[])
-
{
-
box obj = new box();
-
obj.width = 10;
-
obj.height = 2;
-
obj.length = 10;
-
int y = obj.width * obj.height * obj.length;
-
System.out.print(y);
-
}
-
}
Correct Answer
B. 200
Explanation
The program defines a class called "box" with three integer variables: width, height, and length. It also defines another class called "mainclass" with a main method. Inside the main method, an object of the "box" class is created and assigned values to its width, height, and length variables. Then, the variables are multiplied together and stored in the variable "y". Finally, the value of "y" is printed. In this case, the width is 10, the height is 2, and the length is 10, so the output will be 10 * 2 * 10 = 200.
17.
Which of these access specifiers must be used for main() method?
Correct Answer
B. Public
Explanation
The main() method in Java must be declared as public. This is because the main() method serves as the entry point for the Java program, and it needs to be accessible to the Java Virtual Machine (JVM) in order to execute the program. Declaring it as public allows other classes and packages to access and invoke the main() method.
18.
Which of these access specifier must be used for class so that it can be inherited by another subclass?
Correct Answer
A. Public
Explanation
The access specifier "public" must be used for a class so that it can be inherited by another subclass. This means that the class can be accessed and inherited by any other class, regardless of its location or package. The "public" access specifier provides the highest level of accessibility for a class.
19.
Which method can be defined only once in a program?
Correct Answer
A. Main method
Explanation
The main method can be defined only once in a program because it serves as the entry point for the program's execution. It is the method that is called first when the program is run, and it is responsible for starting the program's execution and invoking other methods as needed. Defining multiple main methods in a program would create ambiguity and confusion, as the program would not know which method to call first. Therefore, the main method is unique and can only be defined once in a program.
20.
Using which of the following, multiple inheritance in Java can be implemented?
Correct Answer
A. Interfaces
Explanation
Multiple inheritance in Java can be implemented using interfaces. In Java, a class can implement multiple interfaces, allowing it to inherit the methods and constants defined in those interfaces. This allows for the implementation of multiple inheritance-like behavior, where a class can inherit from multiple sources. Interfaces provide a way to achieve this without the complexities and ambiguity that can arise from traditional multiple inheritance. By implementing multiple interfaces, a class can inherit and utilize the functionality defined in each interface, providing a flexible and modular approach to inheritance in Java.
21.
What is not type of inheritance?
Correct Answer
B. Double inheritance
Explanation
Double inheritance is not a type of inheritance because it does not exist in object-oriented programming. Inheritance is a mechanism where a class inherits properties and behaviors from another class. Single inheritance allows a class to inherit from only one superclass, while multiple inheritance allows a class to inherit from multiple superclasses. Hierarchical inheritance is a type of inheritance where multiple classes inherit from a single superclass. However, double inheritance is not a recognized concept in inheritance.
22.
Which of the following is used for implementing inheritance through an interface?
Correct Answer
D. Implements
Explanation
The correct answer is "implements". In Java, the "implements" keyword is used to implement inheritance through an interface. When a class implements an interface, it inherits all the methods declared in that interface and must provide implementations for those methods. This allows for code reusability and polymorphism, as multiple classes can implement the same interface and be treated interchangeably.
23.
What would be the result if a class extends two interfaces and both have a method with same name and signature?
Correct Answer
B. Compile time error
Explanation
When a class extends two interfaces and both interfaces have a method with the same name and signature, it will result in a compile-time error. This is because the class is required to provide an implementation for all the methods defined in the interfaces it extends. Since both interfaces have a method with the same name and signature, it is ambiguous for the class to determine which method to implement. Therefore, the compiler will throw an error indicating that the class must resolve the ambiguity by providing its own implementation for the conflicting method.
24.
Which of these keywords are used to define an abstract class?
Correct Answer
C. Abstrat
Explanation
The correct answer is "abstract". In object-oriented programming, the "abstract" keyword is used to define an abstract class. An abstract class cannot be instantiated and is meant to be a blueprint for other classes to inherit from. It can contain both abstract and non-abstract methods, and any class that inherits from it must implement the abstract methods. The other options mentioned, "abst", "Abstrat", and "static class", are not valid keywords for defining an abstract class.
25.
Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?
Correct Answer
A. Do-while
Explanation
The do-while loop will execute the body of the loop even when the condition controlling the loop is initially false. This is because the condition is checked at the end of the loop iteration, so the body of the loop will always execute at least once before the condition is evaluated.
26.
What is true about a break?
Correct Answer
B. Break halts the execution and forces the control out of the loop
Explanation
A break statement in programming is used to terminate the current loop and force the control to exit the loop. Once a break statement is encountered, the execution of the loop is immediately halted and the control is transferred to the next statement after the loop. This means that the remaining iterations of the loop are skipped, and the program continues executing from the point immediately after the loop. Therefore, the given answer "Break halts the execution and forces the control out of the loop" is true.
27.
Which of the following is not a decision making statement?
Correct Answer
D. do-while
Explanation
A do-while statement is not a decision-making statement because it is a looping statement. It executes a block of code repeatedly until a specified condition becomes false. In contrast, if, if-else, and switch statements are decision-making statements that allow the program to make decisions and choose different paths of execution based on certain conditions.
28.
The while loop repeats a set of code while the condition is not met?
Correct Answer
B. False
Explanation
The while loop repeats a set of code while the condition is met, not while the condition is not met. Therefore, the correct answer is False.
29.
What is the output of this program?
-
class operators
-
{
-
public static void main(String args[])
-
{
-
int var1 = 5;
-
int var2 = 6;
-
int var3;
-
var3 = ++ var2 * var1 / var2 + var2;
-
System.out.print(var3);
-
}
-
}
Correct Answer
C. 12
Explanation
The program initializes three variables, var1 with a value of 5, var2 with a value of 6, and var3. The expression var3 = ++var2 * var1 / var2 + var2 is then evaluated.
The prefix increment operator (++var2) increases the value of var2 by 1 before the multiplication operation. So, var2 becomes 7.
Then, the multiplication operation is performed: 7 * 5 = 35.
Next, the division operation is performed: 35 / 7 = 5.
Finally, the addition operation is performed: 5 + 7 = 12.
Therefore, the output of the program is 12.
30.
Which of these keywords is used to define packages in Java?
Correct Answer
C. C) package
Explanation
The correct answer is "c) package". In Java, the keyword "package" is used to define packages. Packages are used to organize and group related classes and interfaces together. By using packages, it becomes easier to manage and maintain large-scale Java applications. The package keyword is always written in lowercase.
31.
Which of these access specifiers can be used for a class so that its members can be accessed by a different class in the different package?
Correct Answer
A. A) Public
Explanation
The correct answer is "a) Public". The "public" access specifier allows the class members to be accessed by a different class in a different package. Public access specifier has the widest scope and allows unrestricted access to the class members from any other class in any package.
32.
An exception is an event, which occurs during the execution of a program that disrupts the normal flow of the program's instructions.
Correct Answer
A. True
Explanation
This statement is true because an exception is indeed an event that can occur during the execution of a program, causing it to deviate from its normal flow. When an exception is encountered, the program's instructions are interrupted, and the control is transferred to a specific exception-handling routine. This allows the program to handle and recover from unexpected errors or exceptional conditions that may arise during its execution.
33.
Java Virtual Machine is independent
Correct Answer
B. False
Explanation
The statement "Java Virtual Machine is independent" is false. The Java Virtual Machine (JVM) is not independent as it is platform-dependent. JVM is designed to run Java bytecode, which is a platform-independent intermediate code. However, the JVM itself needs to be installed on the specific operating system in order to execute the bytecode. Therefore, the JVM is not independent and requires platform-specific implementations.
34.
What is the return type of lambda expression?
Correct Answer
D. D) Function
Explanation
The return type of a lambda expression can be any valid data type, including primitive types, objects, or even void. In this case, the correct answer is d) Function, which represents a lambda expression that returns a value.
35.
Lambda Expression are useful to write shorthand Code and hence saves the effort of writing lengthy Code.
Correct Answer
A. True
Explanation
Lambda expressions in programming languages like Java are indeed useful for writing shorthand code. They allow developers to write concise and compact code by eliminating the need for writing lengthy and repetitive code blocks. Lambda expressions are particularly handy when working with functional interfaces, allowing for more efficient and readable code. Therefore, the given answer, "True," is correct.