0% found this document useful (0 votes)
79 views

Java Mcqs

The document contains examples of Java code and questions about Java programming concepts like variables, data types, operators, and OOPs concepts. It tests knowledge of Java syntax, semantics and basics of the language.

Uploaded by

Vineel Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Java Mcqs

The document contains examples of Java code and questions about Java programming concepts like variables, data types, operators, and OOPs concepts. It tests knowledge of Java syntax, semantics and basics of the language.

Uploaded by

Vineel Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

1. Which of these cannot be used for a variable name in Java?

a) identifier & keyword


b) identifier
c) keyword
d) none of the mentioned

2 What is the extension of java code files?


a) .js
b) .txt
c) .class
d) .java

3 class output {
public static void main(String args[])
{
double a, b,c;
a = 3.0/0;
b = 0/4.0;
c=0/0.0;

System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
NaN
b) Infinity
c) 0.0
d) all of the mentioned

4 Which of the following is not an OOPS concept in Java?


a) Polymorphism
b) Inheritance
c) Compilation
d) Encapsulation

5 class variable_scope
{
public static void main(String args[])
{
int x;
x = 5;
{
int y = 6;
System.out.print(x + " " + y);
}
System.out.println(x + " " + y);
}
}
a) Compilation error
b) Runtime error
c) 5 6 5 6
d) 5 6 5

6 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

7 Which of these are selection statements in Java?


a) break
b) continue
c) for()
d) if()
8 What will be the output of the following Java code?

class output
{
public static void main(String args[])
{
String c = "Hello i love java";
boolean var;
var = c.startsWith("hello");
System.out.println(var);
}
}
a) 0
b) true
c) 1
d) false

9 class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Quiz");
StringBuffer s2 = s1.reverse();
System.out.println(s2);
}
}
a) QuizziuQ
b) ziuQQuiz
c) Quiz
d) ziuQ

10 class Output
{
public static void main(String args[])
{
Integer i = new Integer(257);
byte x = i.byteValue();
System.out.print(x);
}
}
a) 257
b) 256
c) 1
d) 0

11 class Output
{
public static void main(String args[])
{
double x = 2.0;
double y = 3.0;
double z = Math.pow( x, y );
System.out.print(z);
}
}
a) 9.0
b) 8.0
c) 4.0
d) 2.0

12
Modulus operator, %, can be applied to which of these?
a) Integers
b) Floating – point numbers
c) Both Integers and floating – point numbers
d) None of the mentioned

13 With x = 0, which of the following are legal lines of Java code for changing the
value of x to 1?

1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;
a) 1, 2 & 3
b) 1 & 4
c) 1, 2, 3 & 4
d) 3 & 2

14 Which of these is not a bitwise operator?


a) &
b) &=
c) |=
d) <=
15 public static void main(String args[])
{
int a = 1;
int b = 2;
int c = 3;
a |= 4;
b >>= 1;
c <<= 1;
a ^= c;
System.out.println(a + " " + b + " " + c);
}
}
a) 3 1 6
b) 2 2 3
c) 2 3 4
d) 3 3 6

16
What will be the output of the following Java program?

class Output
{
public static void main(String args[])
{
int arr[] = {1, 2, 3, 4, 5};
for ( int i = 0; i < arr.length - 2; ++i)
System.out.println(arr[i] + " ");
}
}
a) 1 2 3 4 5
b) 1 2 3 4
c) 1 2
d) 1 2 3
17 class String_demo
{
public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
System.out.println(s);
}
}
a) abc
b) a
c) b
d) c
18
Which of these have highest precedence?
a) ()
b) ++
c) *
d) >>
19
What is the order of precedence (highest to lowest) of following operators?

1. &
2. ^
3. ?:
20 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);
}
}
a) 10
b) 11
c) 12
d) 56
21
What is the numerical range of a char data type in Java?
a) 0 to 256
b) -128 to 127
c) 0 to 65535
d) 0 to 32767

22 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

23 Which of these values can a boolean variable contain?


a) True & False
b) 0 & 1
c) Any integer value
d) true

You might also like