1) What is the output for the following program
class Java
{
public static void main(String[] args)
{
test('a');
}
public static void test(int a)
{
System.out.println("int");
}
public static void test(double d)
{
System.out.println("double");
}
}
a) double
b) int
c) Compile Time Error
d) None of the Above
2) What is the output for the following program
class Java1
{
public static void main(String[] args)
{
String str = "String";
char ch = 'a';
System.out.println(str+ch);
}
}
a) String97
b) Compile Time Error
c) Stringa
d) None of the Above
3) Choose the wrong one
a) return 10>20 ;
b) return 'a'+10;
c) return (int a = 10);
d) return 10>20 ? 10 : 20;
4) What is the output for the following program
class Java2
{
public static void main(String[] args)
{
System.out.println(test(20));
}
public static int test(int a)
{
return a=10;
}
}
a) 20
b) compile time error
c) 10
d) None of the Above
5) Who will do the early binding?
a) Interpreter
b) JIT
c) Java Compiler
d) JVM
6) Which one of the following will not done by the compiler
a) Converting source file into class file
b) Importing java.lang package
c) Narrowing
d) Static binding
7) Choose the correct one with respect to Method overloading
a) Methods return type should be same
b) Methods should be non static
c) Modifiers should be same
d) None of the Above
8) what is the correct Syntax to import only Scanner class
a) import java.lang.Scanner;
b) Import java.util.Scanner;
c) import java.util.*;
d) import java.util.Scanner;
9) Which members can be called from one class into another class?
a) Only static members
b) Only Non static members
c) Only imported members
d) Both static and non static members
10) which one is the correct when the return type of the method is void
a) We can use return with value
b) we can't use return
c) we can use return without data
d) we can use return with expression
11) what is return
a) It is a control transfer statement
b) It is a keyword
c) It will return the value and control
d) All of the Above
12) What is the output for the following program
class Java3
{
public static void main(String[] args)
{
System.out.println(get('a'));
}
public static int get(char ch)
{
return ch;
}
}
a) a
b) 97
c) Compile time error
d) None of the Above
13) Which one we cannot use in the return
a) Value
b) Variable
c) Statement
d) Expression
14) What is actual arguments
a) Variable created in the method declaration
b) Variable created in the method block
c) Value passed in the method calling Statement
d) Value returned by the method
15) Formal arguments are
a) Static variables
b) Local variables
c) non static variables
d) None of the Above
16) What is the output for the following program
class Java4
{
public static void main(String[] args)
{
add(10,20);
}
public static short add(short a,short b)
{
return a+b;
}
}
a) No output
b) Compile time error
c) 30
d) None of the Above
17) Which one is correct increasing order
a) byte>short>int>long>float>double
b) byte<short<int<float<long<double
c) byte<short<int<long<float<double
d) byte<short<int<float<double<long
18) What is the output for the following program
class Java5
{
public static void main(String[] args)
{
int a = 10;
test(10+"Perseverence");
}
public static void test(String b)
{
System.out.println("All the best");
}
}
a) No output
b) Compile time error
c) It will not execute
d) All the best
19) Who will do Implicit type casting
a) JVM
b) Java compiler
c) Programmer
d) JIT compiler
20) Which one is correct about Compound assignment operator
a) Type casting
b) Self Updating
c) Reduce code redundancy
d) All of the Above
21) Which one in the following is compile time error
a) true && false
b) ! true == false
c) true || ! false
d) None of the Above
22) What is the output for the following program
class Java6
{
public static void main(String[] args)
{
int a = 5;
System.out.println(3 + a+=5);
}
}
a) 13
b) 8
c) Compile time error
d) None of the Above
23) What is the output for the following program
class Java6
{
public static void main(String[] args)
{
int a=10;
System.out.println( a+(a=a++));
}
}
a) 22
b) 21
c) Compile time error
d) 20
24) What should be the operand for Increment and Decrement operator
a) We can use String data
b) We can use number data directly
c) We can use boolean data
d) We can use only variable
25) What is the output for the following program
class Java7
{
public static void main(String[] args)
{
int a = 20;
int res = a<20 ? a : 'a';
System.out.println(res);
}
}
a) Compile time error
b) 20
c) 97
d) 'a'
26) What we cannot use in the place of Operand2 and Operand3 in Conditional
Operator
a) Expression
b) Statement
c) data
d) Variable
27) Which one of the following is Compile time Success
a) "Hii" >= "Hii"
b) true > false
c) 'a'>=97
d) "Hello" != true
28)
int a = 10;
int b = 20;
int res = a+b;
What is the correct expression we have to use to print the output like 10+20=30
a) a+b=res
b) a+"+"+b+"="+res
c) a"+"b"="res
d) We cannot print like 10+20=30
29) Which one is not the behavior of the Operator in java
a) Assigning the data to the variable
b) Performing Type casting
c) Updating the variable
d) Declare a Variable
30) Which operator will have polymorphic nature
a) &&
b) ++
c) +
d) %
31) Which operator will have Right to Left associativity
a) Dot(.) Operator
b) Compound Assignment operators
c) Relational operators
d) Arithmetic Operators
32) Which member that we can access by using Dot(.) Operator
a) Class members
b) Object members
c) Both (a) and (b)
d) None of the Above
33) What is the output for the following program
class Java8
{
public static void main(String[] args)
{
{
int a = 20;
}
int a= 30;
System.out.println(a);
}
}
a) Run time error
b) 30
c) 20
d) Compile time error
34) In main method (public static void main(String[] args) ) args is
a) keyword
b) identifier
c) Literal
d) Symbol
35) What is keyword
a) Predefined Word
b) Reserved word
c) Compiler aware word
d) All of the Above
-----------------------------------------------------------------------------------
---------------------------------------------------
1) What is the output for the following program
class Java1
{
public static void main(String[] args)
{
String str = "String";
char ch = 'a';
System.out.println(str+ch);
}
}
a) String97
b) Compile Time Error
c) Stringa
d) None of the Above
2) Which one in the following is compile time error
a) true && false
b) ! true == false
c) true || ! false
d) None of the Above
3) What should be the operand for Increment and Decrement operator
a) We can use String data
b) We can use number data directly
c) We can use boolean data
d) We can use only variable
4) What is the output for the following program
class Java7
{
public static void main(String[] args)
{
int a = 20;
int res = a<20 ? true : false;
System.out.println(res);
}
}
a) Compile time error
b) false
c) true
d) none of the above
5) Which one of the following is Compile time Success
a) "Hii" >= "Hii"
b) true > false
c) 'a'>=97
d) "Hello" != true
6)
int a = 10;
int b = 20;
int res = a+b;
What is the correct expression we have to use to print the output like 10+20=30
a) a+b=res
b) a+"+"+b+"="+res
c) a"+"b"="res
d) We cannot print like 10+20=30
7 ) Which operator will have polymorphic nature
a) &&
b) ++
c) +
d) %
8) What is the output for the following program
class Java8
{
public static void main(String[] args)
{
{
int a = 20;
}
int a= 30;
System.out.println(a);
}
}
a) Run time error
b) 30
c) 20
d) Compile time error
9) What is keyword
a) Predefined Word
b) Reserved word
c) Compiler aware word
d) All of the Above
10) In main method (public static void main(String[] args) ) main is
a) keyword
b) identifier
c) Literal
d) Symbol
11)What is the output for the following program
public class Test1 {
public static void main(String[] args) {
int a = 10, b = 20;
int res = a>b++ && ++a<b ? b++ : b--;
System.out.print(a);
System.out.print(b);
}
}
a)1021
b)1122
c)1121
d)1020
12)Which of the following is Syntax for Declaration and Initialization of a
Variable.
a) datatype Identifier;
b) identifier=Value/Vatiable/Expression;
c) datatype Identifier=Value/Variable/Expression;
d) datatype = Identifier
13)Which of the following Operator returns Boolean value
a) Assignment Operator.
b) Decrement Operator.
c) Relational Operator.
d) Compound Assignment Operator
14) What should be the length of the character data
a) length should be 0
b) length should be 1
c) length can be anything
d) none of the above
15) What we can store inside the non-primitive variable
a) we can store Boolean data
b) we can store Number data
c) We can store reference of an Object
d) none of the above
16 )What is the output for the following program
class Demo1
{
public static void main(String[] @args)
{
System.out.println("All the best");
}
}
a) All the best
b) It won’t print anything
c) compile time error
d) none of the above
17) Which of these is ternary operator
a) Relational Operator
b) Conditional Operator
c) Logical AND
d) Compound assignment operator
18) What is the output for the following program
class Demo1
{
public static void main(String[] @args)
{
System.out.print(100);
System.out.println("Hello");
System.out.print();
}
}
a) 100Hello
b) Compile time error
c) 10
Hello
d) None of the above
19) What is the correct syntax of the conditional (ternary) operator in Java?
a) operand1 ? operand2 : operand3
b) operand1 : operand2 ? operand3
c) operand1 ? operand2 , operand3
d) operand1 : operand2 , operand3
20) What is the output for the following program
class Demo1
{
public static void main(String[] args)
{
int a = 10;
System.out.println("a");
}
}
a) 10
b) compile time error
c) a
d) 97
21) Why java is platform independent?
a) Because of java compiler
b) Because of source file
c) Because of main method
d) Because of Byte code and JVM
22) Which of the following data types is used to store a decimal number in Java?
a) int
b) double
c) boolean
d) char
23) Which of the following is the correct way to declare a float variable in Java?
a) float f = 10.5;
b) float f = 10.5f;
c) float f = 10.5F;
d) Both 2 and 3
24) What is the output for the following program
public class Main {
public static void main(String[] args) {
int x = 5;
{
int x = 10;
System.out.print(x);
}
System.out.print(x);
}
}
a) 105
b) Compilation Error
c) 1010
d) None of the above
25) What is the role of a compiler?
a) Executes the program directly
b) Translates high-level code to machine code
c) Interprets the code line by line
d) Creates an interactive environment for the programmer
26) What is a datatype in Java?
a) A set of values that a variable can hold
b) The name given to a variable
c) To specify the type of data that variable can store
d) It is a compiler
27) Which of the following is not a keyword in Java?
a) static
b) void
c) true
d) public
28) What we can use in the main method
a) only Expressions
b) only conditions
c) only statements
d) None of the above
29) Can we compile an empty Java source file (without any code) in Java?
A) No, we cannot compile an empty source file.
B) Yes, we can compile an empty source file, but no class file will be generated.
C) Yes, we can compile an empty source file, and a class file will be generated.
D) None of the above
30) What is the purpose of Interpreter
a) It will compile the Java source code
b) It will load the java classes
c) It will generate byte code
d) Line by line execution