JAVA MCQs-1




  1. Which of the following is true?
    1. Java uses only interpreter
    2. Java uses only compiler
    3. Java uses both interpreter and compiler:
    4. None of the above.

  2. A Java file with extension .class contains
    1. Java source code
    2. HTML tags
    3. Java Byte code
    4. A program file written in Java programming language

  3. Which of the following features are not common in both Java and C++
    1. The class declaration
    2. The access modifiers
    3. The encapsulation of data and methods.
    4. Multiple inheritance from class

  4. What is the value returned by the method f () defined below:
    public static int f(int x, int y) { return (x> y) ? y: x; }
    1. The sum of and y that is, x + y
    2. The difference of x and y that is, x- y
    3. The maximum of x and y that is, the larger value of x and y
    4. The minimum of x and y that is the smaller value of x and y.

  5. A platform is the hardware or software environment in which a program runs. Which of the following is are Java platform component(s)?
    1. HTML
    2. Java Virtual Machine
    3. Java Application Programming Interface (API)
    4. Hot Java

  6. Consider the following program.

    public class Question 1 {
    public static void main (String args[]){
    for (int a=l;a<3 a+=3)
    System.out.println (--a) :
    }
    }

    What will be the output of the program if it is executed?
    1. 0
    2. 01
    3. 012
    4. 0123

  7. Following is a piece of code where some parts of a statement is missing

    public class Question 3 {
    public static void main (String args[]){
    char arr[]=('a', 'b','c', 'd','e'};
    System.out.println (-------------);
    }
    }
    In the following, some options are given.
    You have to choose the correct option for the argument in System.out.print() function to print the first and the last characters in the array arr.
    1. arr[arr.length-1] + arr[o]
    2. arr [0] + arr[arr.length-1]
    3. +arr[0] + arr[arr.length-1]
    4. a + arr[arr.length-1]+ arr

  8. Which of the following cannot be used for a variable name in Java?
    1. identifier
    2. final
    3. malloc
    4. calloc


  9. public class Operator {
    public static void main(String args){
    String stl="NAGA";
    String str2="RAJU";
    System.out.println (strl+str2); //Statement 1
    int a=20;
    int b=10;
    System.out.println(a+b);
    //Statement 2
    }
    }

    Which of the following statement(s) is/are correct?
    1. Except + (plus) operator all other operators are overloaded in java
    2. NAGARAJU
    3. 1020
    4. 30

  10. Which of the following is an incorrect array declaration?
    1. int[] a = new int[20];
    2. int [] a;
    3. int[][] a = new int[20];
    4. int[][] a = {(1, 2, 4), (1, 2, 4)}


No comments:

Post a Comment