Quiz : OCA Java SE 8 : Java data types practice

Java data types practice
Total Question : 10

Quiz online to practice OCA SE 8 this test cover the primitive data types in Java, including scenar-ios when a particular primitive data type should orcan’t be used. Similarities and differences between the primitive data types.

  1. Given:

    int myChar = 97;
    int yourChar = 98;
    System.out.print((char)myChar + (char)yourChar);
    int age = 20;System.out.print(" ");
    System.out.print((float)age);

    What is the output?

  2. Which of the options are correct for the following code?

    public class Prim {                                // line 1
        public static void main(String[] args) {       // line 2
            char a = 'a';                              // line 3
            char b = -10;                              // line 4
            char c = '1';                              // line 5
            integer d = 1000;                          // line 6
            System.out.println(++a + b++ * c - d);     // line 7
        }                                              // line 8
    }                                                  // line 9
  3. What is the output of the following code?

    public class Foo {
        public static void main(String[] args) {
            int a = 10;
            long b = 20;
            short c = 30;
            System.out.println(++a + b++ * c);
        }
    }
  4. Given:

    Boolean buy = new Boolean(true);
    Boolean sell = new Boolean(true);
    System.out.print(buy == sell);
    boolean buyPrim = buy.booleanValue();
    System.out.print(!buyPrim);
    System.out.print(buy && sell);

    What is the output?

  5. Which  of  the  following  options  contain  correct  code  to  declare  and  initialize variables to store whole numbers?

  6. Select the options that, when inserted at //INSERT CODE HERE, will make the fol-lowing code output a value of 11:

    public class IncrementNum {
        public static void main(String[] args) {
            int ctr = 50;
            // INSERT CODE HERE
            System.out.println(ctr % 20);
        }
    }
  7. What is the output of the following code?

    int a = 10;
    int b = 20;
    int c = (a * (b + 2)) - 10-4 * ((2*2) - 6;
    System.out.println(c);
  8. What is true about the following lines of code?

    boolean b = false;
    int i = 90;
    System.out.println(i >= b);
  9. Examine the following code and select the correct options:

    public class Prim {                                          // line 1
        public static void main(String[] args) {                 // line 2
            int num1 = 12;                                       // line 3
            float num2 = 17.8f;                                  // line 4
            boolean eJavaResult = true;                          // line 5
            boolean returnVal = num1 >= 12 && num2 < 4.567       // line 6
                                           || eJavaResult == true;
            System.out.println(returnVal);                       // line 7
        }                                                        // line 8
    }                                                            // line 9
  10. Given:

    boolean myBool = false;                               // line 1
    int yourInt = 10;                                     // line 2
    float hisFloat = 19.54f;                              // line 3
    System.out.println(hisFloat = yourInt);               // line 4
    System.out.println(yourInt > 10);                     // line 5
    System.out.println(myBool = false);                   // line 6

    What is the result?


Retated posts