Java Evaluation Quiz Practice Set - 1

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Hc.csi2014
H
Hc.csi2014
Community Contributor
Quizzes Created: 1 | Total Attempts: 317
| Attempts: 317 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. 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;

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.

Submit
Please wait...
About This Quiz
Evaluation 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"

2. Which one is a valid declaration of a boolean?

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".

Submit
3. Which will legally declare, construct, and initialize an array?

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.

Submit
4. Which is a valid keyword in java?

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.

Submit
5. Which is a valid declarations of a String?

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.

Submit
6. 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 ");        }    }}

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".

Submit
7. What will be the output of the program?public class Foo{     public static void main(String[] args)    {        try        {            return;        }        finally        {            System.out.println( "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.

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

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.

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

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( )".

Submit
10. 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);    }}

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.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

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
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Public interface Foo{    int k = 4; /* Line 3 */}Which...
Which one is a valid declaration of a boolean?
Which will legally declare, construct, and initialize an array?
Which is a valid keyword in java?
Which is a valid declarations of a String?
What will be the output of the program?public class...
What will be the output of the program?public class...
      What is the value of "d" after...
Public class Test { }What is the prototype of the default constructor?
Public class Myfile{    public static void main...
Alert!

Advertisement