Quiz Time
Java

Java is a powerful general-purpose programming language.

Course Related Quiz

# Quiz
1
Discuss
JRE

Which component is responsible to run java program?

  • 1]

    JVM

  • 2]

    JDK

  • 3]

    JIT

  • 4]

    JRE

Solution
2
Discuss
JDK

Which component is used to compile, debug and execute java program?

  • 1]

    JVM

  • 2]

    JDK

  • 3]

    JRE

  • 4]

    JIT

Solution
3
Discuss
JVM

What is the extension of java code files?

  • 1]

    .class

  • 2]

    .java

  • 3]

    .txt

  • 4]

    .js

Solution
4
Discuss
JVM

Which component is responsible for converting bytecode into machine specific code?

  • 1]

    JVM

  • 2]

    JDK

  • 3]

    JIT

  • 4]

    JRE

Solution
5
Discuss
JVM

Which component is responsible to optimize bytecode to machine code?

  • 1]

    JVM

  • 2]

    JDK

  • 3]

    JIT

  • 4]

    JRE

Solution
6
Discuss
JVM

What is the extension of compiled java classes?

  • 1]

    .class

  • 2]

    .java

  • 3]

    .txt

  • 4]

    .js

Solution
7
Discuss
JVM

How can we identify whether a compilation unit is class or interface from a .class file?

  • 1]

    Java source file header

  • 2]

    Extension of compilation unit

  • 3]

    We cannot differentiate between class and interface

  • 4]

    The class or interface name should be postfixed with unit type

Solution
8
Discuss
JVM

What is use of interpreter?

  • 1]

    They convert bytecode to machine language code

  • 2]

    They read high level code and execute them

  • 3]

    They are intermediated between JIT and JVM

  • 4]

    It is a synonym for JIT

Solution

An interpreter is a software program that implements JVM (Java Virtual Machine) and converts bytecode into machine format, which is then executed on the host machine.

9
Discuss
JVM

JVM Stands for  ________________.

  • 1]

    Java Virtual Management

  • 2]

    Java Virtual Memory

  • 3]

    Java Virtual Machanism

  • 4]

    Java Virtual Machine

Solution
10
Discuss
Variable

Which of these is long data type literal?

  • 1]

     0x99fffL

  • 2]

    ABCDEFG

  • 3]

    0x99fffa

  • 4]

    99671246

Solution
11
Discuss
Variable

Which of these can be returned by the operator &?

  • 1]

    Integer

  • 2]

    Boolean

  • 3]

    Character

  • 4]

    Integer or Boolean

Solution
12
Discuss
Variable

What will be the output of the following Java program?

    public class dynamic_initialization 
    {
        public static void main(String args[]) 
        {
            double a, b;
            a = 3.0;
            b = 4.0;
	    double c = Math.sqrt(a * a + b * b);
	    System.out.println(c);
        } 
    }

 

  • 1]

    5.0

  • 2]

    25.0

  • 3]

    7.0

  • 4]

    Compilation Error

Solution
13
Discuss
Variable

What will be the output of the following Java program?

    public 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);
        } 
    }

 

  • 1]

    5 6 5 6

  • 2]

    5 6 5

  • 3]

    Runtime error

  • 4]

    Compilation error

Solution
14
Discuss
Variable

What will be the output of the following Java program?

    public class array_output 
    {
        public static void main(String args[]) 
        {
       	    int array_variable [] = new int[10];
	    for (int i = 0; i < 10; ++i) {
                array_variable[i] = i/2;
                array_variable[i]++;
                System.out.print(array_variable[i] + " ");
                i++;
            }
 
        } 
    }

 

  • 1]

    0 2 4 6 8

  • 2]

    1 2 3 4 5

  • 3]

     0 1 2 3 4 5 6 7 8 9

  • 4]

    1 2 3 4 5 6 7 8 9 10

Solution
15
Discuss
Variable

What will be the output of the following Java program?

    public class evaluate 
    {
        public static void main(String args[]) 
        {
            int a[] = {1,2,3,4,5};
	    int d[] = a;
	    int sum = 0;
	    for (int j = 0; j < 3; ++j)
                sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);
	    System.out.println(sum);
        } 
    }

 

  • 1]

    38

  • 2]

    39

  • 3]

    40

  • 4]

    41

Solution
16
Discuss
Variable

Which of these can not be used for a variable name in Java?

  • 1]

    identifier

  • 2]

    keyword

  • 3]

    identifier & keyword

  • 4]

    none of the mentioned

Solution
17
Discuss
Datatype

Which data type value is returned by all transcendental math functions?

  • 1]

    int

  • 2]

    float

  • 3]

    double

  • 4]

    long

Solution
18
Discuss
Datatype

Which of these literals can be contained in float data type variable?

  • 1]

    -1.7e+308

  • 2]

    -3.4e+038

  • 3]

    +1.7e+308

  • 4]

    -3.4e+050

Solution
19
Discuss
Datatype

An expression involving byte, int, and literal numbers is promoted to which of these?

  • 1]

    float

  • 2]

    byte

  • 3]

    long

  • 4]

    int

Solution
20
Discuss
Datatype

Which of the following are legal lines of Java code?

   1. int w = (int)888.8;
   2. byte x = (byte)100L;
   3. long y = (byte)100;
   4. byte z = (byte)100L;
  • 1]

    1 and 2

  • 2]

    2 and 3

  • 3]

    3 and 4

  • 4]

    All statements are correct

Solution
21
Discuss
Datatype

What is the range of byte data type in Java?

  • 1]

    -128 to 127

  • 2]

    -32768 to 32767

  • 3]

    -2147483648 to 2147483647

  • 4]

    None of the mentioned

Solution
22
Discuss
Datatype

What is the range of short data type in Java?

  • 1]

    -128 to 127

  • 2]

    -32768 to 32767

  • 3]

    -2147483648 to 2147483647

  • 4]

    None of the mentioned

Solution
23
Discuss
Datatype

What will be the output of these statement?

public 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);
        } 
    }

 

  • 1]

    Infinity

  • 2]

    0.0

  • 3]

    NaN

  • 4]

    all of the mentioned

Solution
24
Discuss
Datatype

What will be the output of the following Java code? - Average

public class average {
   public static void main(String args[])
     {
         double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
         double result;
         result = 0;
         for (int i = 0; i < 6; ++i) 
         {
           result = result + num[i];
         } 
	    System.out.print(result/6);
 
      } 
  }

 

  • 1]

    16.34

  • 2]

    16.566666644

  • 3]

    16.46666666666667

  • 4]

    16.46666666666666

Solution
25
Discuss
Datatype

What will be the output of the following Java code? - Increment / Decrement

public class increment {
   public static void main(String args[]) 
     {        
         int g = 3;
         System.out.print(++g * 8);
     } 
}

 

  • 1]

    25

  • 2]

    24

  • 3]

    32

  • 4]

    33

Solution
26
Discuss
Datatype

What will be the output of the following Java code? - Area Of Circle

public class area {
        public static void main(String args[]) 
        {    
             double r, pi, a;
             r = 9.8;
             pi = 3.14;
             a = pi * r * r;
             System.out.println(a);
        } 
    }

 

  • 1]

    301.5656

  • 2]

    301

  • 3]

    301.56

  • 4]

    301.56560000

Solution
27
Discuss
Datatype

Which of the below data type doesn’t support overloaded methods for +,-,* and /?

  • 1]

    int

  • 2]

    float

  • 3]

    double

  • 4]

    BigDecimal

Solution
28
Discuss
Datatype

What is the numerical range of a char data type in Java?

  • 1]

    -128 to 127

  • 2]

    0 to 256

  • 3]

    0 to 32767

  • 4]

    0 to 65535

Solution
29
Discuss
Datatype

What is the numerical range of a char data type in Java?Which of these coding types is used for data type characters in Java?

  • 1]

    -128 to 127 ASCII

  • 2]

    0 to 256 ISO-LATIN-1

  • 3]

    0 to 32767 UNICODE

  • 4]

    0 to 65535 UNICODE

Solution
30
Discuss
Datatype

Which of these values can a boolean variable contain?

  • 1]

    True & False

  • 2]

    0 & 1

  • 3]

    Any integer value

  • 4]

    True

Solution
31
Discuss
Datatype

Which one is a valid declaration of a boolean?

  • 1]

    boolean b1 = 1;

  • 2]

    boolean b2 = ‘false’;

  • 3]

    boolean b3 = false;

  • 4]

    boolean b4 = ‘true’

Solution
32
Discuss
Datatype

What is the output of this program?

public class array_output {
        public static void main(String args[]) 
        {    
            char array_variable [] = new char[10];
            for (int i = 0; i < 10; ++i) {
                array_variable[i] = 'i';
                System.out.print(array_variable[i] + "" );
                i++;
            }
        } 
    }

 

  • 1]

    i i i i i

  • 2]

    0 1 2 3 4

  • 3]

    i j k l m

  • 4]

    None of the mentioned

Solution
33
Discuss
Datatype

What is the output of this program?

public class mainclass {
        public static void main(String args[]) 
        {
            char a = 'A';
            a++;
            System.out.print((int)a);
        } 
    }

 

  • 1]

    66

  • 2]

    67

  • 3]

    65

  • 4]

    64

Solution
34
Discuss
Datatype

Which of the following is the advantage of BigDecimal over double?

  • 1]

    Syntax

  • 2]

    Memory usage

  • 3]

    Garbage creation

  • 4]

    Precision

Solution
35
Discuss
Datatype

What is the output of below code snippet?

   double a = 0.02;
   double b = 0.03;
   double c = b - a;
   System.out.println(c);
 
   BigDecimal _a = new BigDecimal("0.02");
   BigDecimal _b = new BigDecimal("0.03");
   BigDecimal _c = b.subtract(_a);
   System.out.println(_c);

 

  • 1]

    0.009999999999999998
    0.01

  • 2]

    0.01
    0.009999999999999998

  • 3]

    0.01
    0.01

  • 4]

    0.009999999999999998
    0.009999999999999998

Solution
36
Discuss
Datatype

What is the base of BigDecimal data type?

  • 1]

    Base 2

  • 2]

    Base 8

  • 3]

    Base 10

  • 4]

    Base e

Solution
37
Discuss
Operator

Which of the following can be operands of arithmetic operators?

  • 1]

    Numeric

  • 2]

    Boolean

  • 3]

    Characters

  • 4]

    Both Numeric & Characters

Solution
38
Discuss
Operator

Modulus operator, %, can be applied to which of these?

  • 1]

    Integers

  • 2]

    Floating – point numbers

  • 3]

    Both Integers and floating – point numbers

  • 4]

    None of the mentioned

Solution
39
Discuss
Operator

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;
  • 1]

    1, 2 & 3

  • 2]

    1 & 4

  • 3]

    1, 2, 3 & 4

  • 4]

    3 & 2

Solution
40
Discuss
Operator

What will be the output of the following Java program?

    class Output 
    {
        public static void main(String args[]) 
        {    
             int a = 1;
             int b = 2;
             int c;
             int d;
             c = ++b;
             d = a++;
             c++;
             b++;
             ++a;
             System.out.println(a + " " + b + " " + c);
        } 
    }

 

  • 1]

    3 2 4

  • 2]

    3 2 3

  • 3]

    2 3 4

  • 4]

    3 4 4

Solution
41
Discuss
Operator

Can 8 byte long data type be automatically type cast to 4 byte float data type?

  • 1]

    true

  • 2]

    false

Solution
42
Discuss
Operator

What will be the output of the following Java program?

    class Modulus 
    {
        public static void main(String args[]) 
        {    
             double a = 25.64;
             int  b = 25;
             a = a % 10;
             b = b % 10;
             System.out.println(a + " "  + b);
        } 
    }

 

  • 1]

    5.640000000000001 5

  • 2]

    5.640000000000001 5.0

  • 3]

    5 5

  • 4]

    5 5.640000000000001

Solution
43
Discuss
Operator

What will be the output of the following Java 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);
 
        } 
    }

 

  • 1]

    1 1

  • 2]

    0 1

  • 3]

    1.5 1

  • 4]

    1.5 1.0

Solution
44
Discuss
Operator

Which of these statements are incorrect?

  • 1]

    Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms

  • 2]

    Assignment operators run faster than their equivalent long forms

  • 3]

    Assignment operators can be used only with numeric and character data type

  • 4]

    None of the mentioned

Solution
45
Discuss
Operator

Decrement operator, −−, decreases the value of variable by what number?

  • 1]

    1

  • 2]

    2

  • 3]

    3

  • 4]

    4

Solution
46
Discuss
Operator

Which of these is not a bitwise operator?

  • 1]

    &

  • 2]

    &=

  • 3]

    |=

  • 4]

    <=

Solution
47
Discuss
Operator

What will be the output of the following Java program?

    class Output 
    {
        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);
        } 
    }

 

  • 1]

    3 1 6

  • 2]

    2 2 3

  • 3]

    2 3 4

  • 4]

    3 3 6

Solution
48
Discuss
Operator

What will be the output of the following Java program?

    class rightshift_operator 
    {
        public static void main(String args[]) 
        {    
             int x; 
             x = 10;
             x = x >> 1;
             System.out.println(x);
        } 
    }

 

  • 1]

    10

  • 2]

    5

  • 3]

    2

  • 4]

    20

Solution
49
Discuss
Operator

What will be the output of the following Java program?

    class leftshift_operator 
    {
        public static void main(String args[]) 
        {        
             byte x = 64;
             int i;
             byte y; 
             i = x << 2;
             y = (byte) (x << 2)
             System.out.print(i + " " + y);
        } 
    }

 

  • 1]

    0 64

  • 2]

    64 0

  • 3]

    0 256

  • 4]

    256 0

Solution
50
Discuss
Operator

What will be the output of the following Java program?

    class bitwise_operator 
    {
        public static void main(String args[]) 
        {    
             int a = 3;
             int b = 6;
 	         int c = a | b;
             int d = a & b;             
             System.out.println(c + " "  + d);
        } 
    }

 

  • 1]

    7 2

  • 2]

    7 7

  • 3]

    7 5

  • 4]

    5 2

Solution
51
Discuss
Operator

What will be the output of the following Java program?

    class bitwise_operator 
    {
        public static void main(String args[])
        {
            int var1 = 42;
            int var2 = ~var1;
            System.out.print(var1 + " " + var2);     	
        } 
    }

 

  • 1]

    42 42

  • 2]

    43 43

  • 3]

    42 -43

  • 4]

    42 43

Solution
52
Discuss
Operator

Which of these statements are incorrect?

  • 1]

    The left shift operator, <<, shifts all of the bits in a value to the left specified number of times

  • 2]

    The right shift operator, >>, shifts all of the bits in a value to the right specified number of time

  • 3]

    The left shift operator can be used as an alternative to multiplying by 2

  • 4]

    The right shift operator automatically fills the higher order bits with 0

Solution
53
Discuss
Operator

Which right shift operator preserves the sign of the value?

  • 1]

    <<

  • 2]

    >>

  • 3]

    <<=

  • 4]

    >>=

Solution
54
Discuss
Operator

 On applying Left shift operator, <<, on integer bits are lost one they are shifted past which position bit?

  • 1]

    1

  • 2]

    32

  • 3]

    33

  • 4]

    31

Solution
55
Discuss
Operator

Which operator is used to invert all the digits in a binary representation of a number?

  • 1]

    ~

  • 2]

    <<<

  • 3]

    >>>

  • 4]

    ^

Solution
56
Discuss
Operator

What is the output of relational operators?

  • 1]

    Integer

  • 2]

    Boolean

  • 3]

    Characters

  • 4]

    Double

Solution
57
Discuss
Operator

What will be the output of the following Java code?

    class Output 
    {
        public static void main(String args[]) 
        {    
             boolean a = true;
             boolean b = false;
             boolean c = a ^ b;
             System.out.println(!c);
        } 
    }

 

  • 1]

    0

  • 2]

    1

  • 3]

    true

  • 4]

    false

Solution
58
Discuss
Operator

What will be the output of the following Java code?

    class Output 
    {
        public static void main(String args[]) 
        {    
             int x , y = 1;
             x = 10;
             if (x != 10 && x / 0 == 0)
                 System.out.println(y);
             else
                 System.out.println(++y);
        } 
    }

 

  • 1]

    1

  • 2]

    2

  • 3]

    Runtime error owing to division by zero in if condition

  • 4]

    Unpredictable behavior of program

Solution
59
Discuss
Operator

What will be the output of the following Java code?

    class ternary_operator 
    {
        public static void main(String args[]) 
        {        
             int x = 3;
             int y = ~ x;
             int z;
             z = x > y ? x : y;
             System.out.print(z);
        } 
    }

 

  • 1]

    0

  • 2]

    1

  • 3]

    3

  • 4]

    -4

Solution
60
Discuss
Operator

What will be the output of the following Java code?

    class bool_operator 
    {
        public static void main(String args[]) 
        {    
             boolean a = true;
             boolean b = !true;
             boolean c = a | b;
 	     boolean d = a & b;
             boolean e = d ? b : c;
             System.out.println(d + " " + e);
        } 
    }

 

  • 1]

    false false

  • 2]

    true ture

  • 3]

    true false

  • 4]

    false true

Solution
61
Discuss
Operator

What will be the output of the following Java code?

    class Relational_operator 
    {
        public static void main(String args[])
        {
            int var1 = 5; 
            int var2 = 6;
            System.out.print(var1 > var2);
        } 
    }

 

  • 1]

    1

  • 2]

    0

  • 3]

    true

  • 4]

    false

Solution
62
Discuss
Operator

Which of these statements is correct?

  • 1]

    true and false are numeric values 1 and 0

  • 2]

    true and false are numeric values 0 and 1

  • 3]

    true is any non zero value and false is 0

  • 4]

    true and false are non numeric values

Solution
63
Discuss
Operator

Which of these operators can skip evaluating right hand operand?

  • 1]

    !

  • 2]

    |

  • 3]

    &

  • 4]

    &&

Solution
64
Discuss
Operator

Which of the following operators can operate on a boolean variable?

   1. &&
   2. ==
   3. ?:
   4. +=
  • 1]

    3 & 2

  • 2]

     1 & 4

  • 3]

     1, 2 & 4

  • 4]

    1, 2 & 3

Solution
65
Discuss
Operator

Which of these is returned by “greater than”, “less than” and “equal to” operators?

  • 1]

    Integers

  • 2]

    Floating – point numbers

  • 3]

    Boolean

  • 4]

    None of the mentioned

Solution
66
Discuss
Operator

What will be the output of the following Java program?

class Output 
{
        public static void main(String args[]) 
        {    
             int a,b,c,d;
             a=b=c=d=20
            a+=b-=c*=d/=20
           System.out.println(a+" "+b+" "+c+" "+d);
 
        } 
}

 

  • 1]

    compile time error

  • 2]

    runtime error

  • 3]

    a=20 b=0 c=20 d=1

  • 4]

    none of the mentioned

Solution
67
Discuss
Operator

Which of these lines of Java code will give better performance?

   1. a | 4 + c >> b & 7; 
   2. (a | ((( 4 * c ) >> b ) & 7 ))
  • 1]

    1 will give better performance as it has no parentheses

  • 2]

    2 will give better performance as it has parentheses

  • 3]

    Both 1 & 2 will give equal performance

  • 4]

    Dependent on the computer system

Solution
68
Discuss
Operator

What will be the output of the following Java code?

class Output 
{
        public static void main(String args[]) 
        {    
             int x=y=z=20;
 
        } 
}

 

  • 1]

    compile and runs fine

  • 2]

    20

  • 3]

    run time error

  • 4]

    compile time error

Solution
69
Discuss
Operator

What will be the output of the following Java code?

    class operators 
    {
        public static void main(String args[]) 
        {    
             int x = 8;
             System.out.println(++x * 3 + " " + x);
        } 
    }

 

  • 1]

    24 8

  • 2]

    24 9

  • 3]

    27 8

  • 4]

    27 9

Solution
70
Discuss
Operator

What will be the output of the following Java code?

    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);
        } 
    }

 

  • 1]

    10

  • 2]

    11

  • 3]

    12

  • 4]

    56

Solution
71
Discuss
Operator

Which of these statements are incorrect?

  • 1]

    Equal to operator has least precedence

  • 2]

    Brackets () have highest precedence

  • 3]

    Division operator, /, has higher precedence than multiplication operato

  • 4]

    Addition operator, +, and subtraction operator have equal precedence

Solution
72
Discuss
Operator

What is the order of precedence (highest to lowest) of following operators?

    1. &    
    2. ^
    3. ?:
  • 1]

    1 -> 2 -> 3

  • 2]

    2 -> 1 -> 3

  • 3]

    3 -> 2 -> 1

  • 4]

    2 -> 3 -> 1

Solution
73
Discuss
Operator

 What is the value stored in x in the following lines of Java code?

   int x, y, z;
    x = 0;
    y = 1;
    x = y = z = 8;
  • 1]

    0

  • 2]

    1

  • 3]

    9

  • 4]

    8

Solution
74
Discuss
Operator

What should be expression1 evaluate to in using ternary operator as in this line?

 expression1 ?  expression2  :  expression3
  • 1]

    Integer

  • 2]

    Floating – point numbers

  • 3]

    Boolean

  • 4]

    None of the mentioned

Solution
75
Discuss
Operator

Which of these have highest precedence?

  • 1]

    ()

  • 2]

    ++

  • 3]

    *

  • 4]

    >>

Solution
76
Discuss
If-else

Which of these are selection statements in Java?

  • 1]

    if()

  • 2]

    for()

  • 3]

    continue

  • 4]

    break

Solution
77
Discuss
If-else

What will be the output of the following Java program?

    class selection_statements 
    {
        public static void main(String args[])
        {
            int var1 = 5; 
            int var2 = 6;
            if ((var2 = 1) == var1)
                System.out.print(var2);
            else 
                System.out.print(++var2);
        } 
    }

 

  • 1]

    1

  • 2]

    2

  • 3]

    3

  • 4]

    4

Solution
78
Discuss
If-else

What will be the output of the following Java program?

    class jump_statments 
    {
        public static void main(String args[]) 
        {        
             int x = 2;
             int y = 0;
             for ( ; y < 10; ++y) 
             {
                 if (y % x == 0) 
                     continue;  
                 else if (y == 8)
                      break;
                 else
                    System.out.print(y + " ");
             }
        } 
    }

 

  • 1]

    1 3 5 7

  • 2]

    2 4 6 8

  • 3]

    1 3 5 7 9

  • 4]

    1 2 3 4 5 6 7 8 9

Solution
79
Discuss
If-else

What would be the output of the following code snippet if variable a=10?

if(a<=0)
{
   if(a==0)
   {
     System.out.println("1 ");
   }
   else 
   { 
      System.out.println("2 ");
   }
}
System.out.println("3 ");

 

  • 1]

    1 2

  • 2]

    2 3

  • 3]

    1 3

  • 4]

    3

Solution
80
Discuss
Switch

Which of these selection statements test only for equality?

  • 1]

    if

  • 2]

    switch

  • 3]

    if & switch

  • 4]

    none of the mentioned

Solution
81
Discuss
Switch

Which of this statement is incorrect?

  • 1]

    switch statement is more efficient than a set of nested ifs

  • 2]

    two case constants in the same switch can have identical values

  • 3]

    switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression

  • 4]

    it is possible to create a nested switch statements

Solution
82
Discuss
Switch

What will be the output of the following Java program?

    class Output 
    {
        public static void main(String args[]) 
        {    
             int a = 5;
             int b = 10;
             first: 
             {
                second: 
                {
                   third: 
                   { 
                       if (a ==  b >> 1)
                           break second;
                   }
                   System.out.println(a);
                }
                System.out.println(b);
             }
        } 
    }

 

  • 1]

    5 10

  • 2]

    10 5

  • 3]

    5

  • 4]

    10

Solution
83
Discuss
Switch

What is the valid data type for variable “a” to print “Hello World”?

switch(a)
{
   System.out.println("Hello World");
}

 

  • 1]

    int and float

  • 2]

    byte and short

  • 3]

    char and long

  • 4]

    byte and char

Solution
84
Discuss
For

What will be the output of the following Java program?

    class comma_operator 
    {
        public static void main(String args[]) 
        {    
             int sum = 0;
             for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
                 sum += i;
 	     System.out.println(sum);
        } 
    }

 

  • 1]

    5

  • 2]

    6

  • 3]

    14

  • 4]

    compilation error

Solution
85
Discuss
While

What will be the output of the following Java program?

class Output 
{
        public static void main(String args[]) 
        {    
           final int a=10,b=20;
          while(a<b)
          {
 
          System.out.println("Hello");
          }
          System.out.println("World");
 
        } 
}

 

  • 1]

    Hello

  • 2]

    run time error

  • 3]

    Hello world

  • 4]

    compile time error

Solution
86
Discuss
While

The while loop repeats a set of code while the condition is not met?

  • 1]

    True

  • 2]

    False

Solution
87
Discuss
do-while

Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

  • 1]

    do-while

  • 2]

    while

  • 3]

    for

  • 4]

    none of the mentioned

Solution
88
Discuss
do-while

What is true about do statement?

  • 1]

    do statement executes the code of a loop at least once

  • 2]

    do statement does not get execute if condition is not matched in the first iteration

  • 3]

    do statement checks the condition at the beginning of the loop

  • 4]

    do statement executes the code more than once always

Solution
89
Discuss
do-while

Which of the following is not a decision making statement?

  • 1]

    if

  • 2]

    if-else

  • 3]

    switch

  • 4]

    do-while

Solution
90
Discuss
break

What is true about a break?

  • 1]

    Break stops the execution of entire program

  • 2]

    Break halts the execution and forces the control out of the loop

  • 3]

    Break forces the control out of the loop and starts the execution of next iteration

  • 4]

    Break halts the execution of the loop for certain time frame

Solution
91
Discuss
break

Which of the following is used with the switch statement?

  • 1]

    Continue

  • 2]

    Exit

  • 3]

    break

  • 4]

    do

Solution
92
Discuss
break

From where break statement causes an exit?

  • 1]

    Only from innermost loop

  • 2]

    Terminates a program

  • 3]

    Only from innermost switch

  • 4]

    From innermost loops or switches

Solution
93
Discuss
continue

Which of these jump statements can skip processing the remainder of the code in its body for a particular iteration?

  • 1]

    break

  • 2]

    return

  • 3]

    exit

  • 4]

    continue

Solution
94
Discuss
About OOPs

Which of the following is not OOPS concept in Java?

  • 1]

    Inheritance

  • 2]

    Encapsulation

  • 3]

    Polymorphism

  • 4]

    Compilation

Solution
95
Discuss
About OOPs

What is it called if an object has its own lifecycle and there is no owner?

  • 1]

    Aggregation

  • 2]

    Composition

  • 3]

    Encapsulation

  • 4]

    Association

Solution

An Association uses a relationship where all objects have their own lifecycle and no owner. This occurs where many-to-many relationships are available, instead of one-to-one or one-to-many.

96
Discuss
About OOPs

What is it called where child object gets killed if parent object is killed?

  • 1]

    Aggregation

  • 2]

    Composition

  • 3]

    Encapsulation

  • 4]

    Association

Solution
97
Discuss
About OOPs

What is it called where object has its own lifecycle and child object cannot belong to another parent object?

  • 1]

    Aggregation

  • 2]

    Composition

  • 3]

    Encapsulation

  • 4]

    Association

Solution
98
Discuss
Inheritance

Which of this keyword must be used to inherit a class?

  • 1]

    super

  • 2]

    this

  • 3]

    extent

  • 4]

    extends

Solution
99
Discuss
Inheritance

What will be the output of the following Java program?

    class A 
    {
        public int i;
        public int j;
        A() 
        {
            i = 1;
            j = 2;
	}
    }    
    class B extends A 
    {
        int a;
        B() 
        {
            super();
        } 
    }    
    class super_use 
    {
        public static void main(String args[])
        {
            B obj = new B();
            System.out.println(obj.i + " " + obj.j)     
        }
   }

 

  • 1]

    1 2
     

  • 2]

    2 1

  • 3]

    Runtime Error

  • 4]

    Compilation Error

Solution
100
Discuss
Inheritance

What will be the output of the following Java program?

    class A 
    {
        int i;
    }    
    class B extends A 
    {
        int j;
        void display() 
        {
            super.i = j + 1;
            System.out.println(j + " " + i);
        }
    }    
    class inheritance 
    {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }

 

  • 1]

    2 2

  • 2]

    3 3

  • 3]

    2 3

  • 4]

    3 2

Solution
101
Discuss
Inheritance

What will be the output of the following Java program?

    class A 
    {
        int i;
        void display() 
        {
            System.out.println(i);
        }
    }    
    class B extends A 
    {
        int j;
        void display() 
        {
            System.out.println(j);
        }
    }    
    class inheritance_demo 
    {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }

 

  • 1]

    0

  • 2]

    1

  • 3]

    2

  • 4]

    Compilation Error

Solution
102
Discuss
Inheritance

Which of these is correct way of inheriting class A by class B?

  • 1]

    class B + class A {}

  • 2]

    class B inherits class A {}

  • 3]

    class B extends A {}

  • 4]

    class B extends class A {}

Solution
103
Discuss
Inheritance

 A class member declared protected becomes a member of subclass of which type?

  • 1]

    public member

  • 2]

    private member

  • 3]

    protected member

  • 4]

    static member

Solution
104
Discuss
Inheritance

What is not type of inheritance?

  • 1]

    Single inheritance

  • 2]

    Double inheritance

  • 3]

    Hierarchical inheritance

  • 4]

     Multiple inheritance

Solution
105
Discuss
Inheritance

Does Java support multiple level inheritance?

  • 1]

    True

  • 2]

    False

Solution
106
Discuss
Inheritance

What would be the result if a class extends two interfaces and both have a method with same name and signature? Lets assume that the class is not implementing that method.

  • 1]

    Runtime error

  • 2]

    Compile time error

  • 3]

    Code runs successfully

  • 4]

    First called method is executed successfully

Solution
107
Discuss
Inheritance

Which of the following is used in implementing inheritance through class?

  • 1]

    inherited

  • 2]

    using

  • 3]

    extends

  • 4]

    implements

Solution
108
Discuss
Inheritance

Which of the following is used for implementing inheritance through an interface?

  • 1]

    inherited

  • 2]

    using

  • 3]

    extends

  • 4]

    implements

Solution
109
Discuss
Inheritance

Static members are not inherited to subclass.

  • 1]

    True

  • 2]

    False

Solution
110
Discuss
Inheritance

If super class and subclass have same variable name, which keyword should be used to use super class?

  • 1]

    super

  • 2]

    this

  • 3]

    upper

  • 4]

    classname

Solution
111
Discuss
Inheritance

In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?

  • 1]

    Protected

  • 2]

    Private

  • 3]

    Public

  • 4]

    Static

Solution
112
Discuss
Inheritance

All classes in Java are inherited from which class?

  • 1]

    java.lang.class

  • 2]

    java.class.inherited

  • 3]

    java.class.object

  • 4]

    java.lang.object

Solution
113
Discuss
Inheritance

Using which of the following, multiple inheritance in Java can be implemented?

  • 1]

    Interfaces

  • 2]

    Multithreading

  • 3]

    Protected methods

  • 4]

    Private methods

Solution
114
Discuss
Polymorphism (Runtime & Compile Time)

Which of the following is a type of polymorphism in Java?

  • 1]

    Compile time polymorphism

  • 2]

    Execution time polymorphism

  • 3]

    Multiple polymorphism

  • 4]

    Multilevel polymorphism

Solution
115
Discuss
Polymorphism (Runtime & Compile Time)

When does method overloading is determined?

  • 1]

    At run time

  • 2]

    At compile time

  • 3]

    At coding time

  • 4]

    At execution time

Solution
116
Discuss
Polymorphism (Runtime & Compile Time)

When Overloading does not occur?

  • 1]

    More than one method with same name but different method signature and different number or type of parameters

  • 2]

    More than one method with same name, same signature but different number of signature

  • 3]

    More than one method with same name, same signature, same number of parameters but different type

  • 4]

    More than one method with same name, same number of parameters and type but different signature

Solution
117
Discuss
Polymorphism (Runtime & Compile Time)

Method overriding is combination of inheritance and polymorphism?

  • 1]

    True

  • 2]

    False

Solution
118
Discuss
Polymorphism (Runtime & Compile Time)

What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?

  • 1]

    Method overloading

  • 2]

    Method overriding

  • 3]

    Method hiding

  • 4]

    None of the mentioned

Solution
119
Discuss
Polymorphism (Runtime & Compile Time)

Which of these keywords can be used to prevent Method overriding?

  • 1]

    static

  • 2]

    constant

  • 3]

    protected

  • 4]

    final

Solution
120
Discuss
Polymorphism (Runtime & Compile Time)

Which of these is supported by method overriding in Java?

  • 1]

    Abstraction

  • 2]

    Encapsulation

  • 3]

    Polymorphism

  • 4]

    None of the mentioned

Solution
121
Discuss
Abstraction (Using abstract and interface)

Which concept of Java is a way of converting real world objects in terms of class?

  • 1]

    Polymorphism

  • 2]

    Encapsulation

  • 3]

    Abstraction

  • 4]

    Inheritance

Solution
122
Discuss
Encapsulation

Which concept of Java is achieved by combining methods and attribute into a class?

  • 1]

    Encapsulation

  • 2]

    Inheritance

  • 3]

    Polymorphism

  • 4]

    Abstraction

Solution
# Quiz