1. Which statement is true about Java?
a) Java is a sequence-dependent programming language
b) Java is a code dependent programming language
c) Java is a platform-dependent programming language
d) Java is a platform-independent programming language
2. Which component is used to compile, debug and execute the java programs?
a) JRE
b) JIT
c) JDK
d) JVM
Which of these cannot be used for a variable name in Java?
a) identifier & keyword
b) identifier
c) keyword
d) none of the mentioned
What is the extension of compiled java classes?
a) .txt
b) .js
c) .class
d) .java
Which of the following is FALSE about arrays on Java?
a) A java array is always an object
b) Length of array can be changed after creation of array
c) Arrays in Java are always allocated on heap
Which one of the following is not a Java feature?
a) Object-oriented
b) Use of pointers
c) Portable
d) Dynamic and Extensible
What will be the output of the following Java code?
public class Main
{
public static void main(String[] args) {
int a = 10;
String temp = Integer.toString(a);
System.out.println(temp);
}
}
a) compilation error
b) exception
c) 10
d) 1
What will be the output of the following Java code?
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
a) 32
b) 33
c) 24
d) 25
Java is case sensitive language.
a) True
b) False
Which of the following operator has more precedence?
a) ()
b) ++
c) *
d) >=
Which of the following operators has more precedence in Java?
a) -
b) +
c) *
Which of the following is not an operator in Java?
a) |
b) ^
c) ~
d) <->
Which environment variable is used to set the java path?
a) MAVEN_Path
b) JavaPATH
c) JAVA
d) JAVA_HOME
Which of the following is not an OOPS concept in Java?
a) Polymorphism
b) Inheritance
c) Compilation
d) Encapsulation
What is correct sequence of execution of any Java program?
a) Editing -> Compilation -> Class Loader -> Bytecode Verifier -> Execution
b) Editing -> Bytecode Verifier -> Compilation -> Class Loader -> Execution
c) Editing -> Compilation -> Bytecode Verifier -> Class Loader -> Execution
d) None of the above
What will be the error in the following Java code?
byte b = 50;
b = b * 50;
a) b cannot contain value 50
b) b cannot contain value 100, limited by its range
c) No error in this code
d) * operator has converted b * 50 into int, which cannot be converted to byte without
casting
Find the output of the following program.
public class CppBuzz {
public static void main(String args[]) {
int a =10;
String b = "10+10";
System.out.println(a+b);
}
}
a) 30
b) 1020
c) 10+10+10
d) 1010+10
Find the output of the following program.
public class CppBuzz {
public static void main(String args[]) {
int a =10;
String b = "10";
System.out.println(b+a);
}
}
a) 10+10
b) 1010
c) compilation error
d) Undefined
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i<5; i=5 )
{
System.out.println("Hello");
}
}
}
a) 5
b) 4
c) 2
d) 1
Find the output of the following program.
public class Main
{
public static void main(String[] args) {
String str = "1234";
int a = Integer.parseInt(str);
System.out.println(a);
}
}
a) 123
b) 1234
c) 12340
d) Compilation Error
Find the output of the following program.
public class Main
{
public static void main(String[] args) {
String str = "1234.34";
Float a = Float.parseFloat(str);
System.out.println(a);
}
}
a) 1234.00
b) 1234.34
c) 1234
d) Exception
Find the output of the following program.
public class Main
{
public static int ret(){
return 0;
}
public static void main(String[] args) {
int a = 0;
if(ret()==0)
System.out.print("Sun");
System.out.println("Moon");
}
}
a) sun
b) sunmoon
c) nothing is printed
d) Compilation Error
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i>5; )
{
System.out.println("Hello");
}
}
}
a) 0
b) 4
c) 2
d) 1
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i<5; )
{
System.out.println("Hello");
}
}
}
a) 0
b) 1
c) 2
d) Infinite times
How many times 'Hello' is printed?
public class CppBuzz {
public static void main(String[] args){
for(int i = 0; i<5; i++)
{
System.out.println("Hello");
i++;
i--;
}
}
}
a) 5
b) 4
c) 3
d) 2
Which of these are Access Modifiers in java?
a) default
b) public
c) protected
d) All of these
Which of these are selection statements in Java?
a) break
b) continue
c) for()
d) if()
Find the output of the following program.
public class Solution{
public static void main(String[] args){
short x = 10;
x = x * 5;
System.out.print(x);
}
}
a) 50
b) 10
c) Compile error
d) Exception
Find the output of the following program.
public class Main
{
public static void main(String[] args) {
int arr[] = {'a','b','c','d','e'};
for(int i = 0 ; i<5; i++){
System.out.print(" "+ (char)arr[i]);
}
}
}
a) a b c d e
b) 96 97 98 99 101
c) 65 66 67 68 69
d) None of the above
Find the output of the following program.
public class Main
{
public static void main(String[] args) {
int arr[] = {1,2,3,4,5};
int count = 0;
for(int i = 0 ; i<5; i++ ){
if(arr[i]%2==0)
arr[i] *= 2;
System.out.print(arr[i]);
}
}
}
a) 12345
b) 135
c) 22222
d) 14385
Find the output of the following program.
public class Main
{
public static void main(String[] args) {
int arr[] = {1,2,3,4,5};
int count = 0;
for(int i = 0 ; i<5; i++ ){
if(arr[i]%2==0)
count++;
}
System.out.print(count);
}
}
a) 3
b) 2
c) 1
d) 0
An array is a group of similar type of datatype.
a) True
b) False
Find the output of the following program.
public class CppBuzz{
public static void main(String[] args){
int a = 10;
System.out.println(a++);
a++;
}
}
a) 10
b) 11
c) 12
d) 13
Find the output of the following program.
public class MyClass {
public static void main(String[] args){
int a = 10;
System.out.println(++a++);
}
}
a) 10
b) 11
c) 12
d) Compilation Error
What will be the output of the following Java code?
class box
{
int width;
int height;
int length;
}
class main
{
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);
}
}
a) 100
b) 400
c) 200
d) 12
What will be the output of the following Java code?
public class CppBuzz {
public static void main(String[] args){
int a = 5+5*2+2*2+(2*3);
System.out.println(a);
}
}
a) 138
b) 264
c) 41
d) 25
What will be the output of the following Java program?
public class CppBuzz {
public static void main(String[] args){
int a = 10;
System.out.println(a*a--);
}
}
a) 100
b) 90
c) 81
d) 80
What will be the output of the following Java program?
public class CppBuzz{
public static void main(String[] args){
int a = 5;
a +=5;
switch(a){
case 5: System.out.print("5");break;
case 10: System.out.print("10");
System.out.print(((a%2 ==0) ? "-even-" : "-odd-"));
default: System.out.print("0");
}
}
a) compilation error
b) 10-even-
c) 10-odd-
d) 10-even-0
What will be the output of the following Java program?
public class CppBuzz{
public static void main(String[] args){
int a = 5;
a +=5;
switch(a){
case 5: System.out.print("5");break;
case 10: System.out.print("10");
System.out.println(((a%2 ==0) ? "-even-" : "-odd-"));
break;
default: System.out.print("0");
}
}
a) compilation error
b) 10-even-
c) 10-even-0
d) 10-odd
What will be the output of the following Java program?
public class CppBuzz{
public static void main(String[] args){
int a = -5;
a +=5;
switch(a){
case 5: System.out.print("5");break;
case 10: System.out.print("10");
default: System.out.print("0");
}
}
a) 5
b) 10
c) 100
d) 0
What will be the output of the following Java program?
1. class Output
2. {
3. public static void main(String args[])
4. {
5. int arr[] = {1, 2, 3, 4, 5};
6. for ( int i = 0; i < arr.length - 2; ++i)
7. System.out.println(arr[i] + " ");
8. }
9. }
a) 1 2 3 4 5
b) 1 2 3 4
c) 1 2
d) 1 2 3
What will be the output of the following Java program?
1. class Output
2. {
3. public static void main(String args[])
4. {
5. double x = 2.0;
6. double y = 3.0;
7. double z = Math.pow( x, y );
8. System.out.print(z);
9. }
10. }
a) 9.0
b) 8.0
c) 4.0
d) 2.0