Java Evaluation Quiz Practice Set - 1

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Hc.csi2014
H
Hc.csi2014
Community Contributor
Quizzes Created: 1 | Total Attempts: 314
Questions: 10 | Attempts: 314

SettingsSettingsSettings
Java Quizzes & Trivia

This quiz is conducted as part of the activity based class and its score will be considered for the continuous evaluation of the course "Programming with Java"


Questions and Answers
  • 1. 

    Which will legally declare, construct, and initialize an array?

    • A.

      Int [] myList = {"1", "2", "3"};

    • B.

      Int [] myList = (5, 8, 2);

    • C.

      Int myList [] [] = {4,9,7,0};

    • D.

      Int myList [] = {4, 3, 7};

    Correct Answer
    D. Int myList [] = {4, 3, 7};
    Explanation
    The correct answer is "int myList [] = {4, 3, 7}". This statement declares, constructs, and initializes an array named "myList" of type int. The array is initialized with the values 4, 3, and 7. The square brackets [] indicate that it is an array, and the curly braces {} are used to specify the initial values of the array elements.

    Rate this question:

  • 2. 

    Which is a valid keyword in java?

    • A.

      Interface

    • B.

      String

    • C.

      Float

    • D.

      Unsigned

    Correct Answer
    A. Interface
    Explanation
    In Java, "interface" is a valid keyword. It is used to define a collection of abstract methods, which can be implemented by classes. Interfaces allow for the implementation of multiple inheritance in Java.

    Rate this question:

  • 3. 

    What will be the output of the program?public class Foo{     public static void main(String[] args)    {        try        {            return;        }        finally        {            System.out.println( "Finally" );        }    }}

    • A.

      Finally

    • B.

      Compilation fails.

    • C.

      The code runs with no output.

    • D.

      An exception is thrown at runtime.

    Correct Answer
    A. Finally
    Explanation
    The output of the program will be "Finally". This is because the code inside the finally block will always execute, regardless of whether there is a return statement or an exception thrown in the try block. Therefore, the statement "Finally" will be printed to the console.

    Rate this question:

  • 4. 

    What will be the output of the program?public class MyProgram{    public static void main(String args[])    {        try        {            System.out.print("Hello world ");        }        finally        {            System.out.println("Finally executing ");        }    }}

    • A.

      Nothing. The program will not compile because no exceptions are specified.

    • B.

      Nothing. The program will not compile because no catch clauses are specified.

    • C.

      Hello world.

    • D.

      Hello world Finally executing

    Correct Answer
    D. Hello world Finally executing
    Explanation
    The program will output "Hello world Finally executing". This is because the try block will always execute, and the finally block will also execute regardless of whether an exception is thrown or not. Therefore, the statement "Hello world" will be printed, followed by the statement "Finally executing".

    Rate this question:

  • 5. 

          What is the value of "d" after this line of code has been executed?double d = Math.round ( 2.5 + Math.random() );

    • A.

      2

    • B.

      3

    • C.

      4

    • D.

      2.5

    Correct Answer
    B. 3
    Explanation
    The code snippet is using the Math.round() method to round the result of the expression "2.5 + Math.random()" to the nearest whole number. Since Math.random() generates a random number between 0 (inclusive) and 1 (exclusive), adding it to 2.5 will result in a number between 2.5 and 3.5. Rounding this number will give us 3, so the value of "d" after executing this line of code will be 3.

    Rate this question:

  • 6. 

    Public class Myfile{    public static void main (String[] args)    {        String biz = args[1];        String baz = args[2];        String rip = args[3];        System.out.println("Arg is " + rip);    }}

    • A.

      Java Myfile 222

    • B.

      Java Myfile 1 2 2 3 4

    • C.

      Java Myfile 1 3 2 2

    • D.

      Java Myfile 0 1 2 3

    Correct Answer
    C. Java Myfile 1 3 2 2
    Explanation
    The given correct answer is "java Myfile 1 3 2 2". This is because the program is taking command line arguments and storing them in the "args" array. In the given answer, the first argument "1" is stored in the "biz" variable, the second argument "3" is stored in the "baz" variable, and the third argument "2" is stored in the "rip" variable. Finally, the program prints "Arg is 2" to the console.

    Rate this question:

  • 7. 

    Which one is a valid declaration of a boolean?

    • A.

      Boolean b1 = 0;

    • B.

      Boolean b2 = 'false';

    • C.

      Boolean b3 = false;

    • D.

      Boolean b4 = Boolean.false();

    • E.

      Boolean b5 = no;

    Correct Answer
    C. Boolean b3 = false;
    Explanation
    The correct answer is "boolean b3 = false;". This is a valid declaration of a boolean because it assigns the value "false" to the variable "b3". In Java, boolean variables can only have two possible values: "true" or "false".

    Rate this question:

  • 8. 

    Which is a valid declarations of a String?

    • A.

      String s1 = null;

    • B.

      String s2 = 'null';

    • C.

      String s3 = (String) 'abc';

    • D.

      String s4 = (String) '\ufeed';

    Correct Answer
    A. String s1 = null;
    Explanation
    The correct answer is "String s1 = null;". This is a valid declaration of a String because it assigns a null value to the variable "s1". The other options are not valid declarations of a String. "String s2 = 'null';" is incorrect because it uses single quotes instead of double quotes to denote a String literal. "String s3 = (String) 'abc';" is incorrect because it tries to cast a character literal to a String, which is not allowed. "String s4 = (String) '\ufeed';" is incorrect because it tries to cast a character literal to a String, but the character literal is not a valid Unicode escape sequence.

    Rate this question:

  • 9. 

    Public interface Foo{    int k = 4; /* Line 3 */}Which three piece of codes are equivalent to line 3?
    1. final int k = 4;
    2. public int k = 4;
    3. static int k = 4;
    4. abstract int k = 4;
    5. volatile int k = 4;
    6. protected int k = 4;

    • A.

      1, 2 and 3

    • B.

      2, 3 and 4

    • C.

      3, 4 and 5

    • D.

      4, 5 and 6

    Correct Answer
    A. 1, 2 and 3
    Explanation
    The correct answer is 1, 2 and 3 because all three options declare the variable "k" with the value of 4. Option 1 declares "k" as a final variable, option 2 declares "k" as a public variable, and option 3 declares "k" as a static variable. These options are equivalent to line 3 in the given code.

    Rate this question:

  • 10. 

    Public class Test { }What is the prototype of the default constructor?

    • A.

      Test( )

    • B.

      Test(void)

    • C.

      Public Test( )

    • D.

      Public Test(void)

    Correct Answer
    C. Public Test( )
    Explanation
    The correct answer is "public Test( )". In Java, the prototype of a default constructor is the same as the class name followed by an empty set of parentheses. In this case, the class name is "Test" and the constructor has no parameters, so the correct prototype is "public Test( )".

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 03, 2015
    Quiz Created by
    Hc.csi2014
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.