Fundamental Operators And Wrapper Classes

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 Sadhanaa
S
Sadhanaa
Community Contributor
Quizzes Created: 1 | Total Attempts: 61
Questions: 15 | Attempts: 61

SettingsSettingsSettings
Fundamental Operators And Wrapper Classes - Quiz


Questions and Answers
  • 1. 

    IsNaN is made available in

    • A.

      long

    • B.

      short

    • C.

      double

    • D.

      byte

    Correct Answer
    C. double
    Explanation
    The correct answer is "double" because the isNaN function is made available in the double data type. The isNaN function is used to determine whether a value is NaN (Not-a-Number) or not. The double data type represents double-precision floating-point numbers in Java, which can store very large or very small numbers with decimal points. Therefore, the isNaN function can be used to check if a double value is a valid number or not.

    Rate this question:

  • 2. 

    The three most important methods available in the wrapper classes are:

    • A.

      XxxValue()

    • B.

      Valueof()

    • C.

      ParseXxx()

    • D.

      Xxxvalue()

    • E.

      ValueOf()

    • F.

      ParseXxx()

    Correct Answer(s)
    A. XxxValue()
    C. ParseXxx()
    E. ValueOf()
    Explanation
    The wrapper classes in Java provide methods to convert primitive data types to their corresponding wrapper objects and vice versa. The three most important methods available in the wrapper classes are xxxValue(), parseXxx(), and valueOf().

    The xxxValue() method is used to convert a wrapper object to its corresponding primitive data type. For example, intValue() converts an Integer object to an int.

    The parseXxx() method is used to convert a string representation of a primitive data type to its corresponding wrapper object. For example, parseInt() converts a string to an Integer object.

    The valueOf() method is used to convert a string representation of a primitive data type to its corresponding wrapper object. It is similar to the parseXxx() method but returns a cached instance if available, which can improve performance.

    These methods are essential for converting between primitive data types and their wrapper objects.

    Rate this question:

  • 3. 

    Read the following program   class test {                 public static void main(String [] args)                 {                                 int x = 3;                                 int y = 1;                                 if (x = y)                                                 System.out.println("Equal");                                 else                                                 System.out.println("Not Equal");                 } }   What is the result?

    • A.

      The output is Equal

    • B.

      The output is Not Equal

    • C.

      An error at " if (x = y)" causes compilation to fall.

    • D.

      The program executes but no output is show on console.

    Correct Answer
    C. An error at " if (x = y)" causes compilation to fall.
    Explanation
    The given program contains a mistake in the if statement. Instead of using the equality operator (==), the assignment operator (=) is used. This means that the value of y is assigned to x, and the if statement will always evaluate to true. As a result, the program will not compile and will throw a compilation error.

    Rate this question:

  • 4. 

    What is the output? class Test {     public static void main(String [] args)     {         int x=20;         String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";         System.out.println(sup);     } }

    • A.

      Small

    • B.

      Tiny

    • C.

      Huge

    • D.

      Compilation fails

    Correct Answer
    B. Tiny
    Explanation
    The output of the given code is "Tiny". This is because the ternary operator is used to evaluate the value of the variable "sup". The condition (x < 15) is false, so it moves to the next condition (x < 22), which is true since x = 20. Therefore, the value assigned to "sup" is "tiny" and it is printed as the output.

    Rate this question:

  • 5. 

    Primitive data types

    • A.

      Are also called as objects

    • B.

      Are not objects

    • C.

      Cannot access methods of object class

    • D.

      Can access methods of object class

    Correct Answer(s)
    B. Are not objects
    C. Cannot access methods of object class
    Explanation
    Primitive data types are not objects because they do not have the characteristics of objects, such as having methods and being able to be manipulated using object-oriented programming concepts. Primitive data types are basic data types that are built into the programming language and are used to store simple values like numbers or characters. They are not instances of a class and therefore cannot access methods of the object class, which is a fundamental class in object-oriented programming.

    Rate this question:

  • 6. 

    Which of the following are legal identifiers

    • A.

      2variable

    • B.

      Variable2

    • C.

      _whatavariable

    • D.

      _3_

    • E.

      $anothervar

    • F.

      #myvar

    Correct Answer(s)
    B. Variable2
    C. _whatavariable
    D. _3_
    E. $anothervar
    Explanation
    Legal identifiers in programming are names used to identify variables, functions, or other entities. They must follow certain rules, such as starting with a letter or underscore, and can contain letters, numbers, or underscores. In this question, the identifiers "variable2", "_whatavariable", "_3_", and "$anothervar" all follow these rules and are therefore legal identifiers. On the other hand, "2variable", "#myvar", and "variable2" are not legal identifiers because they start with a number or a special character.

    Rate this question:

  • 7. 

    Class train {                  public static void main(String[] args)                  {                   Integer x = 0;                   int  y= 0;                   for(int z = 0; z < 5; z++)                                   if ((++x > 2) || (++y>1))                                                   x++;                   System.out.println(x + " " + y);                 }   } What is the output of the following program?

    • A.

      8 0

    • B.

      8 1

    • C.

      9 2

    • D.

      9 1

    Correct Answer
    C. 9 2
    Explanation
    The program initializes two variables, x and y, to 0. It then enters a for loop that iterates 5 times. Inside the loop, there is an if statement that checks two conditions. The first condition is (++x > 2), which increments x by 1 and checks if it is greater than 2. The second condition is (++y > 1), which increments y by 1 and checks if it is greater than 1. If either of these conditions is true, x is incremented by 1. After the if statement, the program prints the values of x and y.

    In the first iteration of the loop, x is incremented to 1 and y remains 0, so the output is "1 0". In the second iteration, x is incremented to 2 and y is incremented to 1, so the output is "2 1". In the third iteration, x is incremented to 3 and y is incremented to 2, so the output is "3 2". In the fourth and fifth iterations, x remains 3 and y remains 2, so the output is "3 2" again. Therefore, the correct answer is "9 2".

    Rate this question:

  • 8. 

    The default keyword can be located anywhere in the

    • A.

      Switch block

    • B.

      Switch expression

    • C.

      Switch statement

    • D.

      Switch construct

    Correct Answer
    A. Switch block
    Explanation
    The default keyword can be located anywhere in the switch block. This means that it can be placed within the switch statement, which is the main part of the switch construct. The switch block contains multiple case statements and the default keyword is used to specify the code that should be executed if none of the case statements match the switch expression. By allowing the default keyword to be located anywhere within the switch block, it provides flexibility in organizing the code and makes it easier to understand and maintain.

    Rate this question:

  • 9. 

    Wrapper classes are -----------

    • A.

      Extensible

    • B.

      Immutable

    • C.

      Serializable

    • D.

      All the above

    Correct Answer
    B. Immutable
    Explanation
    Wrapper classes in Java, such as Integer, Double, and Boolean, are immutable. This means that once an object of a wrapper class is created, its value cannot be changed. Any operation that appears to modify the value actually creates a new object. This immutability ensures that the values stored in wrapper classes are consistent and cannot be accidentally modified, providing a level of safety and predictability in Java programs.

    Rate this question:

  • 10. 

    The easiest way to turn a number into a string is to simply concatenate using

    • A.

      +

    • B.

      -

    • C.

      &

    • D.

      *

    Correct Answer
    A. +
    Explanation
    The easiest way to turn a number into a string is to simply concatenate using the "+" operator. This operator is used to combine or join two strings together. In this case, by using the "+" operator, the number can be converted into a string by appending it to an empty string. This will result in the number being converted into a string and can be used or displayed as such.

    Rate this question:

  • 11. 

    What is the output of System.out.println(-3>>>1)?

    • A.

      2147483646

    • B.

      1

    • C.

      2

    • D.

      Cannot be shifted

    Correct Answer
    A. 2147483646
    Explanation
    The output of System.out.println(-3>>>1) is 2147483646. The ">>>" operator is the unsigned right shift operator in Java. When a negative number is right-shifted using the unsigned right shift operator, the sign bit is always set to 0, resulting in a positive number. In this case, -3 is represented in binary as 11111111111111111111111111111101. When we right-shift this number by 1 position using the unsigned right shift operator, we get 01111111111111111111111111111110, which is equivalent to 2147483646 in decimal.

    Rate this question:

  • 12. 

       double c=Double.parseDouble("50h");    System.out.println(c);   What is the output of the above program?

    • A.

      50h

    • B.

      This results in compile time error'Number Frame Exception'

    • C.

      This results in runtime error 'Number Format Exception'

    • D.

      50

    Correct Answer
    C. This results in runtime error 'Number Format Exception'
    Explanation
    The given program tries to parse the string "50h" into a double using the Double.parseDouble() method. However, since the string contains a non-numeric character ('h'), it cannot be converted into a valid number format. As a result, a NumberFormatException is thrown at runtime, causing the program to terminate with an error.

    Rate this question:

  • 13. 

       boolean b;    System.out.println(b);   What is the output of the above program?

    • A.

      True

    • B.

      False

    • C.

      Null

    • D.

      0

    Correct Answer
    B. False
    Explanation
    The output of the above program is "False" because the variable "b" is not initialized with any value. In Java, boolean variables have a default value of "false" if not explicitly assigned a value. Therefore, when the program tries to print the value of "b", it will output "false".

    Rate this question:

  • 14. 

    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 contains three elements: 4, 3, and 7.

    Rate this question:

  • 15. 

    What gets printed when the following program is compiled and run. Select the one correct answer.   class test {                 public static void main(String args[]) {                                 int i,j,k,l=0;                                 k = l++;                                 j = ++k;                                 i = j++;                                 System.out.println(i);                                    } }

    • A.

      0

    • B.

      1

    • C.

      2

    • D.

      3

    Correct Answer
    B. 1
    Explanation
    The program initializes four variables i, j, k, and l to 0. The value of l is then assigned to k using the post-increment operator, which means k will be assigned the current value of l (0) and then l will be incremented by 1. Next, k is assigned to j using the pre-increment operator, which means j will be assigned the incremented value of k (1). Finally, j is assigned to i using the post-increment operator, which means i will be assigned the current value of j (1) and then j will be incremented by 1. Therefore, the value of i is 1, which is printed to the console.

    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
  • May 18, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 03, 2011
    Quiz Created by
    Sadhanaa
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.