JAVA

star goldstar goldstar goldstar goldstar greyFemaleMale
50 Questions - Developed by: Elisabeth - Developed on: - 38.207 taken

  • 1
    Suppose s is a string with the value "java. What will be assigned to x if you execute the following code?
  • 2
    Which of the following statements is preferred to create a string "Welcome to Java"?
  • 3
    What is the output of the following code?

    public class Test {
    public static void main(String[] args) {
    String s1 = "Welcome to Java!";
    String s2 = s1;

    if (s1 == s2)
    System.out.println("s1 and s2 reference to the same String object");
    System.out.println("s1 and s2 reference to different String objects");
    }
    }

  • 4
    What is the output of the following code?

    public class Test {
    public static void main(String[ ] args) {
    String s1 = "Welcome to Java!";
    String s2 = "Welcome to Java!";

    if (s1 == s2)
    System.out.println("s1 and s2 reference to the same String object");
    else
    System.out.println("s1 and s2 reference to different String objects");
    }
    }
  • 5
    What is the output of the following code?

    String s = "University";
    s.replace("i", "ABC");
    System.out.println(s);
  • 6
    What is the printout for the first println statement in the main method?

    public class Foo {
    static int I = 0;
    static int j = 0;

    public static void main(String[ ] args) {
    int I = 2;
    int k = 3;
    {
    int j = 3;
    System.out.println("i + j is " + I + j);
    }

    k = I + j;
    System.out.println("k is " + k);
    System.out.println("j is " + j);
    }
    }
  • 7
    What is the return value of "SELECT".substring(0, 5)?
  • 8
    Which of the following is the correct statement to return JAVA?
  • 9
    You can declare two variables with the same name in ____.
  • 10
    Analyze the following code.

    int[ ] list = new int[5];
    list = new int[6];
  • 11
    Analyze the following code.

    public class Test {
    public static void main(String[ ] args) {
    int[ ] x = new int[3];
    System.out.println("x[0] is " + x[0]);
    }
    }
  • 12
    Analyze the following code:

    public class Test {
    public static void main(String[ ] args) {
    int[ ] oldList = {1, 2, 3, 4, 5};
    reverse(oldList);
    for (int I = 0; I < oldList.length; i++)
    System.out.print(oldList[i] + " ");
    }

    public static void reverse(int[ ] list) {
    int[ ] newList = new int[list.length];

    for (int I = 0; I < list.length; i++)
    newList[i] = list[list.length - 1 - i];

    list = newList;
    }
    }
  • 13
    How many elements are in array double[ ] list = new double[5]?
  • 14
    If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________.
  • 15
    If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ________.
  • 16
    The JVM stores the array in an area of memory, called ________, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order.
  • 17
    When invoking a method with an object argument, ________ is passed.
  • 18
    When you pass an array to a method, the method receives ________.
  • 19
    The selectionSort method is defined in this section. What is list1 after executing the following statements?

    double[ ] list1 = {3.1, 3.1, 2.5, 6.4};
    selectionSort(list1);
  • 20
    An object is an instance of a ________.
  • 21
    A method that is associated with an individual object is called ________.
  • 22
    Given the declaration Circle x = new Circle(), which of the following statement is most accurate?
  • 23
    Given the declaration Circle[ ] x = new Circle[10], which of the following statement is most accurate?
  • 24
    The keyword ________ is required to declare a class.
  • 25
    To declare a constant MAX_LENGTH as a member of the class, you write
  • 26
    When you return an array from a method, the method returns ________.
  • 27
    ________ is a construct that defines objects of the same type.
  • 28
    ________ is invoked to create an object.
  • 29
    ________ represents an entity in the real world that can be distinctly identified.
  • 30
    Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement?

    if (x > 0)
    if (y > 0)
    System.out.println("x > 0 and y > 0");
    else if (z > 0)
    System.out.println("x < 0 and z > 0");
  • 31
    The "less than or equal to" comparison operator in Java is ________.
  • 32
    The equal comparison operator in Java is ________.
  • 33
    The following code displays ________.

    double temperature = 50;

    if (temperature >= 100)
    System.out.println("too hot");
    else if (temperature <= 40)
    System.out.println("too cold");
    else
    System.out.println("just right");
  • 34
    What is 1 + 1 + 1 + 1 + 1 == 5?
  • 35
    What is the output of the following code?

    boolean even = false;
    System.out.println((even? "true": "false"));
  • 36
    What is the printout of the following switch statement?

    char ch = 'b';

    switch (ch) {
    case 'a':
    System.out.print(ch);
    case 'b':
    System.out.print(ch);
    case 'c':
    System.out.print(ch);
    case 'd':
    System.out.print(ch);
    }
  • 37
    Which of the following code displays the area of a circle if the radius is positive?
  • 38
    Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?
  • 39
    Analyze the following fragment:

    double sum = 0;
    double d = 0;
    while (d!= 10.0) {
    d += 0.1;
    sum += sum + d;
    }
  • 40
    Do the following two statements in (I) and (II) result in the same value in sum?

    (I):
    for (int I = 0; i<10; ++i) {
    sum += i;
    }

    (II):
    for (int I = 0; i<10; i++) {
    sum += i;
    }
  • 41
    How many times will the following code print "Welcome to Java"?

    int count = 0;
    while (count < 10) {
    System.out.println("Welcome to Java");
    count++;
    }
  • 42
    How many times will the following code print "Welcome to Java"?

    int count = 0;
    do {
    System.out.println("Welcome to Java");
    count++;
    } while (count < 10);
  • 43
    What is the number of iterations in the following loop:

    for (int I = 1; I <= n; i++) {
    // iteration
    }
  • 44
    What is the output for y?

    int y = 0;
    for (int I = 0; i<10; ++i) {
    y += i;
    }
    System.out.println(y);
  • 45
    Will the following program terminate?

    int balance = 10;

    while (true) {
    if (balance < 9) continue;
    balance = balance - 9;
    }
  • 46
    Why do computers use zeros and ones?
  • 47
    ________ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.
  • 48
    Analyze the following code.

    import javax.swing.*;

    public class ShowErrors {
    public static void main(String[ ] args) {
    int i;
    int j;
    String s = JOptionPane.showInputDialog(null, "Enter an integer", "Input",
    JOptionPane.QUESTION_MESSAGE);
    j = Integer.parseInt(s);
    I = (i + 4);
    }
    }
  • 49
    Analyze the following code.

    public class Test {
    public static void main(String[ ] args) {
    int month = 09;
    System.out.println("month is " + month);
    }
    }
  • 50
    If you enter 1 2 3, when you run this program, what will be the output?

    import java.util.Scanner;

    public class Test1 {
    public static void main(String[ ] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Enter three numbers: ");
    double number1 = input.nextDouble();
    double number2 = input.nextDouble();
    double number3 = input.nextDouble();
    // Compute average
    double average = (number1 + number2 + number3) / 3;
    // Display result
    System.out.println(average);
    }
    }

Comments (0)

autorenew