EmSAT Achieve Exam  >  EmSAT Achieve Tests  >  Java for EmSAT Achieve  >  Test: Starting with Java - 2 - EmSAT Achieve MCQ

Test: Starting with Java - 2 - EmSAT Achieve MCQ


Test Description

20 Questions MCQ Test Java for EmSAT Achieve - Test: Starting with Java - 2

Test: Starting with Java - 2 for EmSAT Achieve 2024 is part of Java for EmSAT Achieve preparation. The Test: Starting with Java - 2 questions and answers have been prepared according to the EmSAT Achieve exam syllabus.The Test: Starting with Java - 2 MCQs are made for EmSAT Achieve 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Starting with Java - 2 below.
Solutions of Test: Starting with Java - 2 questions in English are available as part of our Java for EmSAT Achieve for EmSAT Achieve & Test: Starting with Java - 2 solutions in Hindi for Java for EmSAT Achieve course. Download more important topics, notes, lectures and mock test series for EmSAT Achieve Exam by signing up for free. Attempt Test: Starting with Java - 2 | 20 questions in 40 minutes | Mock test for EmSAT Achieve preparation | Free important questions MCQ to study Java for EmSAT Achieve for EmSAT Achieve Exam | Download free PDF with solutions
Test: Starting with Java - 2 - Question 1

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 5;
        int y = x++;
        System.out.println(y);
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 1

The post-increment operator (x++) assigns the current value of x to y and then increments the value of x. Therefore, y will be 5.

Test: Starting with Java - 2 - Question 2

Which of the following is NOT a primitive data type in Java?

Detailed Solution for Test: Starting with Java - 2 - Question 2

In Java, the keyword "string" is not a valid primitive data type. The correct spelling is "String" (with a capital 'S') and it represents a class in Java.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Starting with Java - 2 - Question 3

What is the correct way to declare an array in Java?

Detailed Solution for Test: Starting with Java - 2 - Question 3

The correct way to declare an array in Java is by using the syntax int[] arr; or int arr[];.

Test: Starting with Java - 2 - Question 4

What is the result of the following code?
String str = "Hello World";
System.out.println(str.length());

Detailed Solution for Test: Starting with Java - 2 - Question 4

The length() method is used to get the number of characters in a String. In the given code, the string "Hello World" has 11 characters, so the output will be 11.

Test: Starting with Java - 2 - Question 5

What is the purpose of the 'this' keyword in Java?

Detailed Solution for Test: Starting with Java - 2 - Question 5

The 'this' keyword in Java is used to refer to the current instance of a class. It is typically used to distinguish between instance variables and method parameters/ local variables with the same name.

Test: Starting with Java - 2 - Question 6

What is the output of the following code?
int x = 10;
int y = 5;
boolean result = (x > y) ? true : false;
System.out.println(result);

Detailed Solution for Test: Starting with Java - 2 - Question 6

The expression (x > y) evaluates to true because 10 is greater than 5. Therefore, the value of the 'result' variable will be true, and it will be printed as the output.

Test: Starting with Java - 2 - Question 7

What does the 'static' keyword mean in Java?

Detailed Solution for Test: Starting with Java - 2 - Question 7

The 'static' keyword in Java is used to indicate that a variable or method belongs to the class itself, not to any specific instance of the class.

Test: Starting with Java - 2 - Question 8

What is the output of the following code?
int x = 6;
int y = 3;
System.out.println(x / y);

Detailed Solution for Test: Starting with Java - 2 - Question 8

When both the operands of the division operator (/) are integers, the result will also be an integer. In this case, 6 divided by 3 is equal to 2, so the output will be 2.

Test: Starting with Java - 2 - Question 9

Which of the following statements is true about Java interfaces?

Detailed Solution for Test: Starting with Java - 2 - Question 9

In Java, a class can implement multiple interfaces by using the implements keyword followed by the interface names separated by commas.

Test: Starting with Java - 2 - Question 10

What is the output of the following code?
int x = 5;
int y = 10;
int z = ++x + y--;
System.out.println(z);

Detailed Solution for Test: Starting with Java - 2 - Question 10

The pre-increment operator (++x) increments the value of x before assigning it to the variable y. The post-decrement operator (y--) decrements the value of y after assigning it to the variable z. Therefore, the value of z will be 16.

Test: Starting with Java - 2 - Question 11

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 5;
        int y = 2;
        int result = x % y;
        System.out.println(result);
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 11

The modulo operator (%) returns the remainder of the division operation. In this case, 5 divided by 2 is equal to 1, so the output will be 1.

Test: Starting with Java - 2 - Question 12

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 3;
        int y = 4;
        boolean result = x == y;
        System.out.println(result);
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 12

The equality operator (==) is used to compare if two values are equal. In this case, 3 is not equal to 4, so the result will be false.

Test: Starting with Java - 2 - Question 13

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 10;
        int y = 5;
        if (x > y) {
            System.out.println("x is greater than y");
        } else {
            System.out.println("x is less than or equal to y");
        }
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 13

The condition x > y is true, so the code inside the if block will be executed, and the output will be "x is greater than y".

Test: Starting with Java - 2 - Question 14

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 5;
        int y = 10;
        if (x > y) {
            System.out.println("x is greater than y");
        } else if (x < y) {
            System.out.println("x is less than y");
        } else {
            System.out.println("x is equal to y");
        }
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 14

The condition x < y is true, so the code inside the else if block will be executed, and the output will be "x is less than y".

Test: Starting with Java - 2 - Question 15

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 10;
        int y = 5;
        int z = 7;
        int result = (x > y) ? (x > z) ? x : z : (y > z) ? y : z;
        System.out.println(result);
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 15

The ternary operator is used to choose one value based on a condition. In this case, the condition (x > y) is false, so the value of z will be y, which is 10.

Test: Starting with Java - 2 - Question 16

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 10;
        int y = 5;
        int result = x / y;
        System.out.println(result);
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 16

When both the operands of the division operator (/) are integers, the result will also be an integer. In this case, 10 divided by 5 is equal to 2, so the output will be 2.

Test: Starting with Java - 2 - Question 17

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 6;
        int y = 3;
        boolean result = (x % y == 0) ? true : false;
        System.out.println(result);
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 17

The expression (x % y == 0) checks if x is divisible by y without a remainder. Since 6 divided by 3 has no remainder, the expression is true, and the output will be true.

Test: Starting with Java - 2 - Question 18

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 5;
        int y = 10;
        boolean result = (x < y) ? true : false;
        System.out.println(result);
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 18

The condition (x < y) is true, so the output will be true.

Test: Starting with Java - 2 - Question 19

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 10;
        int y = 5;
        int z = 7;
        int result = (x < y) ? (x < z) ? x : z : (y < z) ? y : z;
        System.out.println(result);
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 19

The ternary operator is used to choose one value based on a condition. In this case, the condition (x < y) is true, so the value of result will be x, which is 5.

Test: Starting with Java - 2 - Question 20

What is the output of the following code?
public class Main {
    public static void main(String[] args) {
        int x = 5;
        int y = 10;
        int result = (x > y) ? x++ : y--;
        System.out.println(result);
    }
}

Detailed Solution for Test: Starting with Java - 2 - Question 20

The ternary operator is used to choose one value based on a condition. In this case, the condition (x > y) is false, so the value of result will be y--, which is 5.

60 videos|37 docs|12 tests
Information about Test: Starting with Java - 2 Page
In this test you can find the Exam questions for Test: Starting with Java - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Starting with Java - 2, EduRev gives you an ample number of Online tests for practice

Top Courses for EmSAT Achieve

60 videos|37 docs|12 tests
Download as PDF

Top Courses for EmSAT Achieve