Java Programming Solved MCQs

Multiple Choice Questions 94 Pages
BS

Contributed by

Bharat Surana
Loading
  • DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE
    -
    45
    www.dacc.edu.in
    PROF . SUPRIYA MANE
    SUBJECT CODE: 501 SUBJECT: JAVA PROGAMMING
    Unit 1 : Introduction to JAVA
    1.Which component is used to compile, debug and execute java program?
    a) JVM
    b) JDK
    c) JIT
    d) JRE
    Answer: b
    Explanation: JDK is a core component of Java Environment and provides all the tools,
    executables and binaries required to compile, debug and execute a Java Program.
    2. Which component is responsible for converting bytecode into machine specific code?
    a) JVM
    b) JDK
    c) JIT
    d) JRE
    Answer: a
    Explanation: JVM is responsible to converting bytecode to the machine specific code. JVM is
    also platform dependent and provides core java functions like garbage collection, memory
    management, security etc.
    3. Which component is responsible to run java program?
    a) JVM
    b) JDK
    c) JIT
    d) JRE
    Answer: d
    Explanation: JRE is the implementation of JVM, it provides platform to execute java programs.

    Page 1

  • DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE
    -
    45
    www.dacc.edu.in
    PROF . SUPRIYA MANE
    4. Which component is responsible to optimize bytecode to machine code?
    a) JVM
    b) JDK
    c) JIT
    d) JRE
    Answer: c
    Explanation: JIT optimizes bytecode to machine specific language code by compiling similar
    bytecodes at the same time. This reduces overall time taken for compilation of bytecode to
    machine specific language.
    5. Which statement is true about java?
    a) Platform independent programming language
    b) Platform dependent programming language
    c) Code dependent programming language
    d) Sequence dependent programming language
    Answer: a
    Explanation: Java is called ‘Platform Independent Language’ as it primarily works on the
    principle of ‘compile once, run everywhere’.
    6. Which of the below is invalid identifier with the main method?
    a) public
    b) static
    c) private
    d) final
    Answer: c
    Explanation: main method cannot be private as it is invoked by external method. Other identifier
    are valid with main method.
    7. What is the extension of java code files?
    a) .class
    b) .java

    Page 2

  • DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE
    -
    45
    www.dacc.edu.in
    PROF . SUPRIYA MANE
    c) .txt
    d) .js
    Answer: b
    Explanation: Java files have .java extension.
    8. What is the extension of compiled java classes?
    a) .class
    b) .java
    c) .txt
    d) .js
    Answer: a
    Explanation: The compiled java files have .class extension.
    9. How can we identify whether a compilation unit is class or interface from a .class file?
    a) Java source file header
    b) Extension of compilation unit
    c) We cannot differentiate between class and interface
    d) The class or interface name should be postfixed with unit type
    Answer: a
    Explanation: The Java source file contains a header that declares the type of class or interface,
    its visibility with respect to other classes, its name and any superclass it may extend, or
    interface it implements.
    10. What is use of interpreter?
    a) They convert bytecode to machine language code
    b) They read high level code and execute them
    c) They are intermediated between JIT and JVM
    d) It is a synonym for JIT
    Answer: b
    Explanation: Interpreters read high level language (interprets it) and execute the program.
    Interpreters are normally not passing through byte-code and jit compilation.

    Page 3

  • DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE
    -
    45
    www.dacc.edu.in
    PROF . SUPRIYA MANE
    11. Which of the following is not OOPS concept in Java?
    a) Inheritance
    b) Encapsulation
    c) Polymorphism
    d) Compilation
    Answer: d
    Explanation: There are 4 OOPS concepts in Java. Inheritance, Encapsulation, Polymorphism
    and Abstraction.
    12. Which of the following is a type of polymorphism in Java?
    a) Compile time polymorphism
    b) Execution time polymorphism
    c) Multiple polymorphism
    d) Multilevel polymorphism
    Answer: a
    Explanation: There are two types of polymorphism in Java. Compile time polymorphism
    (overloading) and runtime polymorphism (overriding).
    13. When does method overloading is determined?
    a) At run time
    b) At compile time
    c) At coding time
    d) At execution time
    Answer: b
    Explanation: Overloading is determined at compile time. Hence, it is also known as compile time
    polymorphism.
    14. When Overloading does not occur?
    a) More than one method with same name but different method signature and different number
    or type of parameters
    b) More than one method with same name, same signature but different number of signature
    c) More than one method with same name, same signature, same number of parameters but

    Page 4

  • DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE
    -
    45
    www.dacc.edu.in
    PROF . SUPRIYA MANE
    different type
    d) More than one method with same name, same number of parameters and type but different
    signature
    Answer: d
    Explanation: Overloading occurs when more than one method with same name but different
    constructor and also when same signature but different number of parameters and/or parameter
    type.
    15. Which concept of Java is a way of converting real world objects in terms of class?
    a) Polymorphism
    b) Encapsulation
    c) Abstraction
    d) Inheritance
    Answer: c
    Explanation: Abstraction is the concept of defining real world objects in terms of classes or
    interfaces.
    16. Which concept of Java is achieved by combining methods and attribute into a class?
    a) Encapsulation
    b) Inheritance
    c) Polymorphism
    d) Abstraction
    Answer: a
    Explanation: Encapsulation is implemented by combining methods and attribute into a class.
    The class acts like a container of encapsulating properties.
    17. What is it called if an object has its own lifecycle and there is no owner?
    a) Aggregation
    b) Composition
    c) Encapsulation
    d) Association
    Answer: d

    Page 5

  • DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE
    -
    45
    www.dacc.edu.in
    PROF . SUPRIYA MANE
    Explanation: It is a relationship where all objects have their own lifecycle and there is no owner.
    This occurs where many to many relationships are available, instead of one to one or one to
    many.
    18. What is it called where child object gets killed if parent object is killed?
    a) Aggregation
    b) Composition
    c) Encapsulation
    d) Association
    Answer: b
    Explanation: Composition occurs when child object gets killed if parent object gets killed.
    Aggregation is also known as strong Aggregation.
    19. What is it called where object has its own lifecycle and child object cannot belong to another
    parent object?
    a) Aggregation
    b) Composition
    c) Encapsulation
    d) Association
    Answer: a
    Explanation: Aggregation occurs when objects have their own life cycle and child object can
    associate with only one parent object.
    20. Method overriding is combination of inheritance and polymorphism?
    a) True
    b) false
    Answer: a
    Explanation: In order for method overriding, method with same signature in both superclass and
    subclass is required with same signature. That satisfies both concepts inheritance and
    polymorphism.

    Page 6

  • DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE
    -
    45
    www.dacc.edu.in
    PROF . SUPRIYA MANE
    21. Which of these operators is used to allocate memory to array variable in Java?
    a) malloc
    b) alloc
    c) new
    d) new malloc
    Answer: c
    Explanation: Operator new allocates a block of memory specified by the size of an array, and
    gives the reference of memory allocated to the array variable.
    22. Which of these is an incorrect array declaration?
    a) int arr[] = new int[5]
    b) int [] arr = new int[5]
    c) int arr[] = new int[5]
    d) int arr[] = int [5] new
    Answer: d
    Explanation: Operator new must be succeeded by array type and array size.
    23. What will be the output of the following Java code?
    int arr[] = new int [5];
    System.out.print(arr);
    a) 0
    b) value stored in arr[0]
    c) 00000
    d) Class name@ hashcode in hexadecimal form
    Answer: d
    Explanation: If we trying to print any reference variable internally, toString() will be called which
    is implemented to return the String in following form:
    classname@hashcode in hexadecimal form

    Page 7

  • DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE
    -
    45
    www.dacc.edu.in
    PROF . SUPRIYA MANE
    24. Which of these is an incorrect Statement?
    a) It is necessary to use new operator to initialize an array
    b) Array can be initialized using comma separated expressions surrounded by curly braces
    c) Array can be initialized when they are declared
    d) None of the mentioned
    Answer: a
    Explanation: Array can be initialized using both new and comma separated expressions
    surrounded by curly braces example : int arr[5] = new int[5]; and int arr[] = { 0, 1, 2, 3, 4};
    25. Which of these is necessary to specify at time of array initialization?
    a) Row
    b) Column
    c) Both Row and Column
    d) None of the mentioned
    Answer: a
    Explanation: None.
    26. What will be the output of the following Java code?
    1.
    class
    array_output
    2.
    {
    3.
    public
    static
    void
    main(String args[])
    4.
    {
    5.
    int
    array_variable [] =
    new
    int
    [10];
    6.
    for
    (
    int
    i = 0; i < 10; ++i)
    7.
    {
    8.
    array_variable[i] = i;
    9.
    System.out.print(array_variable[i] + " ");
    10.
    i++;
    11.
    }
    12.
    }
    13.
    }

    Page 8

  • DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE
    -
    45
    www.dacc.edu.in
    PROF . SUPRIYA MANE
    a) 0 2 4 6 8
    b) 1 3 5 7 9
    c) 0 1 2 3 4 5 6 7 8 9
    d) 1 2 3 4 5 6 7 8 9 10
    Answer: a
    Explanation: When an array is declared using new operator then all of its elements are initialized
    to 0 automatically. for loop body is executed 5 times as whenever controls comes in the loop i
    value is incremented twice, first by i++ in body of loop then by ++i in increment condition of for
    loop.
    output:
    $ javac array_output.java
    $ java array_output
    0 2 4 6 8
    27. What will be the output of the following Java code?
    1.
    class
    multidimention_array
    2.
    {
    3.
    public
    static
    void
    main(String args[])
    4.
    {
    5.
    int
    arr[][] =
    new
    int
    [3][];
    6.
    arr[0] =
    new
    int
    [1];
    7.
    arr[1] =
    new
    int
    [2];
    8.
    arr[2] =
    new
    int
    [3];
    9.
    int
    sum = 0;
    10.
    for
    (
    int
    i = 0; i < 3; ++i)
    11.
    for
    (
    int
    j = 0; j < i + 1; ++j)
    12.
    arr[i][j] = j + 1;
    13.
    for
    (
    int
    i = 0; i < 3; ++i)
    14.
    for
    (
    int
    j = 0; j < i + 1; ++j)
    15.
    sum + = arr[i][j];
    16.
    System.out.print(sum);
    17.
    }

    Page 9

  • DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE
    -
    45
    www.dacc.edu.in
    PROF . SUPRIYA MANE
    18.
    }
    a) 11
    b) 10
    c) 13
    d) 14
    Answer: b
    Explanation: arr[][] is a 2D array, array has been allotted memory in parts. 1st row contains 1
    element, 2nd row contains 2 elements and 3rd row contains 3 elements. each element of array
    is given i + j value in loop. sum contains addition of all the elements of the array.
    output:
    $ javac multidimention_array.java
    $ java multidimention_array
    10
    28. What will be the output of the following Java code?
    1.
    class
    evaluate
    2.
    {
    3.
    public
    static
    void
    main(String args[])
    4.
    {
    5.
    int
    arr[] =
    new
    int
    [] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
    6.
    int
    n = 6;
    7.
    n = arr[arr[n] / 2];
    8.
    System.out.println(arr[n] / 2);
    9.
    }
    10.
    }
    a) 3
    b) 0
    c) 6
    d) 1

    Page 10

Download this file to view remaining 84 pages

logo StudyDocs
StudyDocs is a platform where students and educators can share educational resources such as notes, lecture slides, study guides, and practice exams.

Contacts

Links

Resources

© 2025 StudyDocs. All Rights Reserved.