Fundamental Operators And Wrapper Classes

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 Sadhanaa
S
Sadhanaa
Community Contributor
Quizzes Created: 1 | Total Attempts: 63
| Attempts: 63 | Questions: 15
Please wait...
Question 1 / 15
0 %
0/100
Score 0/100
1. The easiest way to turn a number into a string is to simply concatenate using

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.

Submit
Please wait...
About This Quiz
Fundamental Operators And Wrapper Classes - Quiz

This quiz focuses on fundamental operators and wrapper classes in Java. It tests understanding of methods like isNaN in Double, key methods in wrapper classes, and correct usage... see moreof operators and conditionals in Java programming, enhancing practical Java coding skills. see less

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

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

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

Submit
4. IsNaN is made available in

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.

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

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.

Submit
6. 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?

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.

Submit
7. The default keyword can be located anywhere in the

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.

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

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

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

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.

Submit
10. 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?

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

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

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.

Submit
12. Primitive data types

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.

Submit
13. Wrapper classes are -----------

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.

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

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.

Submit
15. Which of the following are legal identifiers

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.

Submit
View My Results

Quiz Review Timeline (Updated): May 18, 2023 +

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
Cancel
  • All
    All (15)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
The easiest way to turn a number into a string is to simply...
Which will legally declare, construct, and initialize an array?
What is the output?...
IsNaN is made available in
   double c=Double.parseDouble("50h");...
Read the following program...
The default keyword can be located anywhere in the
   boolean b;...
What gets printed when the following program is compiled and run....
Class train...
What is the output of System.out.println(-3>>>1)?
Primitive data types
Wrapper classes are -----------
The three most important methods available in the wrapper classes are:
Which of the following are legal identifiers
Alert!

Advertisement