1.
Which one among these are OOPS features?
Correct Answer
A. Inheritance
Explanation
Inheritance is one of the features of Object-Oriented Programming (OOPS). It allows a class to inherit properties and behaviors from another class, known as the parent or base class. This promotes code reusability and allows for the creation of hierarchical relationships between classes. Inheritance helps in organizing and structuring code by creating a hierarchy of classes, where each class inherits attributes and methods from its parent class. Therefore, inheritance is a fundamental concept in OOPS.
2.
What is the extension for java programs?
Correct Answer
D. .java
Explanation
The extension for Java programs is ".java" because it is the standard file extension used for Java source code files. This extension allows the Java compiler and IDEs to recognize and properly handle the file as a Java program.
3.
Example of compile-time polymorphism.
Correct Answer
A. Method Overloading
Explanation
Method overloading is an example of compile-time polymorphism. It allows multiple methods with the same name but different parameters to coexist in a class. During compilation, the appropriate method is selected based on the number and types of arguments provided. This enables the programmer to perform different operations using the same method name, providing flexibility and code reusability.
4.
What is the data type of array which we used as a parameter to the main method?
Correct Answer
C. String
Explanation
The data type of the array used as a parameter to the main method is String. This is because in Java, the main method can take an array of Strings as a parameter, which allows command-line arguments to be passed to the program.
5.
The main method can be overridden.
Correct Answer
B. False
Explanation
The main method in Java cannot be overridden because it is a static method. Overriding is a concept that applies to instance methods, where a subclass can provide its own implementation of a method defined in the superclass. However, the main method is a special method that serves as the entry point for a Java program, and it is declared as static. Static methods are associated with the class itself, not with any particular instance of the class, so they cannot be overridden. Therefore, the statement that the main method can be overridden is false.
6.
From the following statements which is a disadvantage of an java array?
Correct Answer
D. An array holds only one type of data
Explanation
An array holds only one type of data, which is a disadvantage because it limits the flexibility and versatility of the array. If we need to store different types of data in the same array, we would need to create separate arrays for each type, leading to increased complexity and reduced code efficiency. This limitation can be problematic when dealing with complex data structures or when we want to store heterogeneous data.
7.
Which provides accessibility to classes and interface?
Correct Answer
A. import
Explanation
The "import" keyword in Java provides accessibility to classes and interfaces. It is used to include a package or a specific class from a package, allowing the programmer to use the classes and interfaces defined in that package in their code. By importing the necessary classes and interfaces, the programmer can access their methods, variables, and other members without having to use their fully qualified names.
8.
Why do we need to write static keyword to the main method?
Correct Answer
A. To create single copy
Explanation
The static keyword is used in the main method because it allows the method to be accessed without creating an instance of the class. This means that there is only one copy of the main method that can be accessed by the JVM, making it the entry point for the program. Without the static keyword, multiple copies of the main method would be created, which would cause confusion and potentially lead to errors.
9.
Methods of the interface are _______ in nature.
Correct Answer
A. Abstract
Explanation
The methods of an interface are abstract in nature because they do not have a body or implementation. They only have method signatures, which define the name, parameters, and return type of the method. The actual implementation of the method is provided by the classes that implement the interface. This allows for multiple classes to provide their own implementation of the methods defined in the interface, promoting code reusability and allowing for polymorphism.
10.
What can be accessed or inherited without an actual copy of code to each program?
Correct Answer
C. Package
Explanation
Packages in programming allow for the organization and grouping of related code. They provide a way to access and inherit code without the need for an actual copy in each program. By importing a package, the code contained within it can be accessed and used by different programs. This promotes code reusability and modularity, making it easier to manage and maintain large projects. Therefore, the correct answer is "Package".
11.
Switch is more efficient than nested if or if - else in java.
Correct Answer
A. True
Explanation
The statement is true because a switch statement in Java can be more efficient than using nested if or if-else statements. This is because a switch statement allows for multiple cases to be evaluated at once, while nested if or if-else statements require each condition to be checked one by one. Additionally, a switch statement can be optimized by the Java compiler, resulting in faster execution. Therefore, using a switch statement can improve the efficiency and readability of the code.
12.
Which package includes all the standard classes of java?
Correct Answer
A. java.lang
Explanation
The package "java.lang" includes all the standard classes of Java. This package is automatically imported in every Java program and contains fundamental classes such as String, Integer, Boolean, and Object. These classes provide basic functionality and are essential for writing Java programs.
13.
JVM stands for?
Correct Answer
D. Java Virtual Machine
Explanation
JVM stands for Java Virtual Machine. It is a virtual machine that allows Java programs to run on different platforms without the need for recompilation. The JVM provides a runtime environment for executing Java bytecode, which is generated from Java source code. It is responsible for memory management, garbage collection, and executing the instructions of the Java program. The other options, Java Very Large Machine, Java Verified Machine, and Java Very Small Machine, are not correct definitions for JVM.
14.
Who is also called the father of Java Programming Language?
Correct Answer
A. James Gosling
Explanation
James Gosling is known as the father of Java Programming Language because he is the original designer of the language. He developed Java in the mid-1990s while working at Sun Microsystems. Gosling's contributions to the development of Java include designing its syntax, creating the original compiler and virtual machine, and defining its core libraries. His work has had a significant impact on the field of programming and has made Java one of the most widely used programming languages in the world.
15.
Generally, the string is a sequence of characters, But in java, the string is an _______.
Correct Answer
A. Object
Explanation
In Java, the string is an object. In object-oriented programming, objects are instances of classes that have properties and behaviors. The String class in Java represents a sequence of characters and provides various methods to manipulate and work with strings. Since strings in Java have properties and behaviors, they are considered objects rather than just a sequence of characters.
16.
Which is nothing but a blueprint or a template for creating different objects which define its properties and behaviors?
Correct Answer
B. A class
Explanation
A class is a blueprint or a template for creating different objects. It defines the properties and behaviors that the objects of that class will have. Objects created from a class will have the same structure and behavior as defined in the class. Therefore, a class is the correct answer as it best fits the description of being a blueprint or template for creating objects.
17.
If a class has multiple methods by the same name but different parameters, it is known as?
Correct Answer
B. Method overloading
Explanation
Method overloading occurs when a class has multiple methods with the same name but different parameters. This allows the class to perform different actions based on the type or number of arguments passed to the method. It is a way to create multiple methods with the same name but with different functionality, improving code readability and reusability. This concept is widely used in object-oriented programming languages like Java and C++.
18.
Which specification provides a runtime environment in which java byte code can be executed?
Correct Answer
B. JVM
Explanation
JVM stands for Java Virtual Machine, which is a specification that provides a runtime environment for executing Java byte code. It is responsible for interpreting the byte code and executing the instructions on the underlying hardware or operating system. JVM also provides various services like memory management, garbage collection, and exception handling. JDK (Java Development Kit) is a software development kit that includes tools for developing Java applications, including the JVM. JRE (Java Runtime Environment) is a subset of JDK that only includes the JVM and necessary libraries for running Java applications. Therefore, the correct answer is JVM.
19.
What output you will get if you run this program?
class Modulus {
public static void main(String args[]) {
int x = 42;
double y = 42.25;
System.out.println("x mod 10 = " + x % 10);
System.out.println("y mod 10 = " + y % 10);
}
}
Correct Answer
A. X mod 10 = 2
y mod 10 = 2.25
Explanation
The program calculates the remainder when x and y are divided by 10 using the modulus operator (%). In the case of x, 42 divided by 10 leaves a remainder of 2. In the case of y, 42.25 divided by 10 leaves a remainder of 2.25.
20.
The following Syntax is used for?class Subclass-name extends Superclass-name { //methods and fields }
Correct Answer
C. Inheritance
Explanation
The given syntax is used for inheritance. Inheritance is a mechanism in object-oriented programming where a subclass can inherit the properties and behavior of a superclass. By using the "extends" keyword, the subclass is able to extend or inherit the superclass, allowing it to access its methods and fields. This promotes code reuse and allows for the creation of more specialized classes based on existing ones.
21.
The Object class is not a parent class of all the classes in java by default.
Correct Answer
B. False
Explanation
In Java, the Object class is indeed the parent class of all classes by default. This means that every class in Java directly or indirectly inherits from the Object class. The Object class provides basic methods and functionalities that are common to all objects in Java, such as toString(), equals(), and hashCode(). Therefore, the correct answer is False.
22.
What is the output of this program?class increment {public static void main(String args[]){double var1 = 1 + 5; double var2 = var1 / 4;int var3 = 1 + 5;int var4 = var3 / 4;System.out.print(var2 + " " + var4); } }
Correct Answer
C. 1.5 1
Explanation
The program first assigns the value 1 + 5 (which is 6) to the variable var1, and then divides var1 by 4, resulting in 1.5. Next, it assigns the value 1 + 5 (which is 6) to the variable var3, and then divides var3 by 4, resulting in 1. Finally, it prints the values of var2 and var4, which are 1.5 and 1 respectively.
23.
What is the output of this program?class increment {public static void main(String args[]) { int g = 3;System.out.print(++g * 8);} }
Correct Answer
C. 32
Explanation
The program starts by initializing the variable "g" with the value 3. Then, it uses the pre-increment operator "++g" to increment the value of "g" by 1, resulting in "g" being equal to 4. Next, it multiplies the value of "g" (which is now 4) by 8, resulting in 32. Finally, it prints the value 32 as the output.
24.
Which of these coding types is used for data type characters in Java?
Correct Answer
C. UNICODE
Explanation
UNICODE is the correct answer because it is the coding type used for data type characters in Java. UNICODE is a universal character encoding standard that assigns a unique number to every character, regardless of the platform, program, or language. It allows Java to represent characters from all languages and scripts, making it suitable for internationalization and localization purposes. ASCII and ISO-LATIN-1 are also character encoding standards, but they have limitations in terms of the range of characters they can represent, unlike UNICODE.
25.
Which one is a valid declaration of a boolean?
Correct Answer
C. Boolean b3 = false;
Explanation
The correct answer is "boolean b3 = false;". This is a valid declaration of a boolean because it assigns the value "false" to the variable b3. In Java, booleans can only have two possible values: true or false. The other options, b1 = 1, b2 = 'false', and b4 = 'true', are not valid boolean declarations because they assign values that are not of the boolean type.
26.
What is the output of this program?class mainclass {public static void main(String args[]) {boolean var1 = true;boolean var2 = false;if (var1)System.out.println(var1);elseSystem.out.println(var2);} }
Correct Answer
C. True
Explanation
The output of this program is "true". The program initializes two boolean variables, var1 and var2, with the values true and false respectively. It then checks the condition if (var1), which evaluates to true since var1 is true. Therefore, the program executes the statement System.out.println(var1), which prints the value of var1, which is "true".
27.
Which of these is an incorrect array declaration?
Correct Answer
D. int arr[] = int [5] new
28.
Which of these is an incorrect Statement?
Correct Answer
A. It is necessary to use new operator to initialize an array.
Explanation
The correct answer is "It is necessary to use new operator to initialize an array." This statement is incorrect because arrays can be initialized without using the new operator. Arrays can be initialized using comma separated expressions surrounded by curly braces or they can be initialized when they are declared.
29.
Which of these is a super class of wrappers Double & Integer?
Correct Answer
D. Number
Explanation
The super class of wrappers Double and Integer is Number. The Number class is an abstract class in Java that is the superclass of classes representing numeric values that can be converted to primitive types. Both Double and Integer classes are part of the Number class hierarchy and inherit common methods and properties from the Number class.
30.
Which of these keywords is used by a class to use an interface defined previously?
Correct Answer
C. Implements
Explanation
The keyword "implements" is used by a class to use an interface defined previously. When a class implements an interface, it is required to provide implementations for all the methods declared in that interface. This allows the class to inherit the behavior defined by the interface and also enables polymorphism, as objects of the class can be treated as objects of the interface type.