Java Multiple Choice Question MCQ

Categories: Java MCQ

Ques 1. Who invented Java Programming?

a) Guido van Rossum

b) James Gosling

c) Dennis Ritchie

d) Bjarne Stroustrup

Answer: b


Ques 2. Which statement is true about Java?

a) Java is a sequence-dependent programming language

b) Java is a code dependent programming language

c) Java is a platform-dependent programming language

d) Java is a platform-independent programming language

Answer: d


Ques 3. Which component is used to compile, debug and execute the java programs?

a) JRE

b) JIT

c) JDK

d) JVM

Answer: c


Ques 4. Which one of the following is not a Java feature?

a) Object-oriented

b) Use of pointers

c) Portable

d) Dynamic and Extensible

Answer: b


Ques 5. Which of these cannot be used for a variable name in Java?

a) identifier & keyword

b) identifier

c) keyword

d) none of the mentioned

Answer: c


Ques 6. What is the extension of java code files?

a) .js

b) .txt

c) .class

d) .java

Answer: d


Ques 7. What will be the output of the following Java code?


    class increment {

        public static void main(String args[]) 

        {        

             int g = 3;

             System.out.print(++g * 8);

        } 

    }

a) 32

b) 33

c) 24

d) 25


Answer: a


Ques 8. Which environment variable is used to set the java path?

a) MAVEN_Path

b) JavaPATH

c) JAVA

d) JAVA_HOME

Answer: d


Ques 9. What will be the output of the following Java program?


class output {

        public static void main(String args[]) 

        {

            double a, b,c;

            a = 3.0/0;

            b = 0/4.0;

            c=0/0.0;

 

    System.out.println(a);

            System.out.println(b);

            System.out.println(c);

        } 

    }

a) NaN

b) Infinity

c) 0.0

d) all of the mentioned

Answer: d


Ques 10. Which of the following is not an OOPS concept in Java?

a) Polymorphism

b) Inheritance

c) Compilation

d) Encapsulation

Answer: c


Ques 11. What is not the use of “this” keyword in Java?

a) Referring to the instance variable when a local variable has the same name

b) Passing itself to the method of the same class

c) Passing itself to another method

d) Calling another constructor in constructor chaining

Answer: b


Ques 12. What will be the output of the following Java program?


    class variable_scope 

    {

        public static void main(String args[]) 

        {

            int x;

            x = 5;

            {

        int y = 6;

        System.out.print(x + " " + y);

            }

            System.out.println(x + " " + y);

        } 

    }

a) Compilation error

b) Runtime error

c) 5 6 5 6

d) 5 6 5

Answer: a


Ques 13. What will be the error in the following Java code?


    byte b = 50;

    b = b * 50;

a) b cannot contain value 50

b) b cannot contain value 100, limited by its range

c) No error in this code

d) * operator has converted b * 50 into int, which can not be converted to byte without casting

Answer: d


Ques 14. Which of the following is a type of polymorphism in Java Programming?

a) Multiple polymorphism

b) Compile time polymorphism

c) Multilevel polymorphism

d) Execution time polymorphism

Answer: b


Ques 15. What will be the output of the following Java program?


    class leftshift_operator 

    {

        public static void main(String args[]) 

        {        

             byte x = 64;

             int i;

             byte y; 

             i = x << 2;

             y = (byte) (x << 2);

             System.out.print(i + " " + y);

        } 

    }

a) 0 256

b) 0 64

c) 256 0

d) 64 0

Answer: c


Ques 16. What will be the output of the following Java code?


    class box 

    {

        int width;

        int height;

        int length;

    } 

    class main

    {

        public static void main(String args[]) 

        {        

             box obj = new box();

             obj.width = 10;

             obj.height = 2;

             obj.length = 10;

             int y = obj.width * obj.height * obj.length; 

             System.out.print(y);

        } 

    }

a) 100

b) 400

c) 200

d) 12

Answer: c


Ques 17. What is Truncation in Java?

a) Floating-point value assigned to a Floating type

b) Floating-point value assigned to an integer type

c) Integer value assigned to floating type

d) Integer value assigned to floating type

Answer: b


Ques 18. What will be the output of the following Java program?


    class Output 

    {

        public static void main(String args[])

        {

            int arr[] = {1, 2, 3, 4, 5};

            for ( int i = 0; i < arr.length - 2; ++i)

                System.out.println(arr[i] + " ");

        } 

    }

a) 1 2 3 4 5

b) 1 2 3 4

c) 1 2

d) 1 2 3

Answer: d


Ques 19. What will be the output of the following Java code snippet?


class abc

{

    public static void main(String args[])

    {

        if(args.length>0)

        System.out.println(args.length);

    }

}

a) The snippet compiles and runs but does not print anything

b) The snippet compiles, runs and prints 0

c) The snippet compiles, runs and prints 1

d) The snippet does not compile

Answer: a


Ques 20. What is the extension of compiled java classes?

a) .txt

b) .js

c) .class

d) .java

Answer: c

Top articles
Advantages and Disadvantages of Java Published at:- Java General Interview Questions and Answer Published at:- Java Threads Interview Question and Answer for experienced Published at:- Java Collections Interview Question and Answer for freshers and experienced Published at:- Garbage Collector in Java Frequently Asked Questions and Answers Published at:- Difference between Exception and Error in java Exception Handling Published at:- Java Applets Interview Questions with Answer Published at:- Java Swing Interview Questions with Answer for freshers and experienced Published at:- Java Database Connectivity (JDBC) Interview Question and answer Published at:- Remote Method Invocation (RMI) Interview Question and Answer Published at:- Jakarta Server Page (JSP) programming language Interview Question and Answer Published at:- Write a program in Java to display the first 10 terms of the following series: 10, 20, 30, 40, …….. Published at:- Write the program in Java to display the first ten terms of the following series: 1, 4, 9, 16, Published at:- Write a program in Java to find the sum of the given series: Published at:- Write a program in Java to find the sum of the given series: Published at:- Java Multiple Choice Question MCQ Published at:- Java Multiple Choice Question MCQ Published at:-
R4Rin Team
The content on R4Rin.com website is created by expert teams.