1.
How will you describe Java?
Correct Answer
C. Both Programming Language and Platform
Explanation
Java acts both as a programming language as well as a platform for several applications.
2.
Java Is Structured Programming Language.
Correct Answer
B. False
Explanation
Java is Object Oriented Programming Language.
3.
Which of the following are legal identifiers in Java?
Correct Answer(s)
B. Abc_1
C. OneAbc
E. $while
Explanation
A is wrong as it starts with a digit. D is wrong as it is a keyword. Identifiers in Java must start with a letter, Dollar sign($) or an Underscore(_) and must not be a keyword.
4.
The package __________ is automatically imported in every java program.
Correct Answer(s)
java.lang, java.lang.*, java.lang.*;
Explanation
In every Java program, the package "java.lang" is automatically imported. This package contains fundamental classes and interfaces that are essential for any Java program to run. The wildcard character "*" indicates that all classes and interfaces within the "java.lang" package are imported. Therefore, the correct answer is "java.lang, java.lang.*, java.lang.*".
5.
What will the function Math.ceil(-99.9) return?
Correct Answer
D. -99.0
Explanation
ceil() returns the smallest whole number less than or equal to the given argument. It returns a double type value.
6.
What will be the output of the following code segment?String one="one";String two="two";String One=new String(one);String Two=two;if(one==One)System.out.println("Java is fun!");if(one.equals(One)==true)System.out.println("Programming needs practice.");if(one==Two)System.out.println("OOP is the way!");if(two.equals(Two)==true)System.out.println("Explore the world of Java.");
Correct Answer
C. Programming needs practice
Explore the world of Java.
Explanation
== operator compares the memory locations, which is never same for two different objects whereas equals() compares the contents.
7.
What will be the output of the following code segment?class Number{int a;public static void main(String ar[]){ a=10;int b=20;a=a+b;b=a-b;a=a-b;System.out.println("a = "+a);System.out.println("b = "+b);}}
Correct Answer
E. Compile-time error
Explanation
Non-static variable cannot be referenced from a static context. a is a non-static variable, it cannot be referenced from within main() which is static.
8.
What will the following code segment print?int i;
for(i=1;i<=4;i=i+3);
System.out.println(i);
Correct Answer
D. 7
Explanation
The value will be printed only when the loop is terminated. Since it's a one-line loop so it won't repeat the printing statement. Loop terminated when i becomes 7. So 7 will be printed.
9.
What will be the output of the following code segment?int a = 4, b = 8, c = -5;
System.out.println(a/b+"\n"+(++c*b--)+" "+a--*b/c--);
Correct Answer
A. 0
-32 -7
Explanation
The code segment first performs the division operation a/b, which results in 0. Then, it concatenates the result with the value of (++c*b--) and (a--*b/c--).
The expression (++c*b--) increments the value of c by 1 and multiplies it by b, which is 8. The post-decrement operator (b--) is then applied, reducing the value of b by 1. The result of this expression is -32.
The expression (a--*b/c--) multiplies the value of a (4) by b (7) and divides it by c (-6). The post-decrement operator (a--) is then applied, reducing the value of a by 1. The result of this expression is -7.
Therefore, the output of the code segment is 0 -32 -7.
10.
Which of the following group consists of only Object-Oriented languages?
Correct Answer
E. C++,JAVA,C#
Explanation
The group consisting of C++, JAVA, and C# consists of only Object-Oriented languages. C++ is a general-purpose programming language that supports both procedural and object-oriented programming paradigms. JAVA is a widely used object-oriented programming language known for its platform independence. C# is a modern, general-purpose, object-oriented programming language developed by Microsoft. All three languages have features and syntax that support object-oriented programming concepts such as encapsulation, inheritance, and polymorphism.