Code Baaj

No 1 Digital Knowledge Website

Most 50 Java Interview Question & Answer |


Basic Java (Core Concepts)

  1. Which of the following is not a Java keyword?
    a) static
    b) Boolean
    c) void
    d) private
    → b) Boolean
  2. Which company originally developed Java?
    a) Sun Microsystems
    b) Oracle
    c) IBM
    d) Microsoft
    → a) Sun Microsystems
  3. Which method is the entry point of a Java program?
    a) start()
    b) run()
    c) main()
    d) init()
    → c) main()
  4. What is the default value of an int variable in Java?
    a) 0
    b) null
    c) undefined
    d) 1
    → a) 0
  5. Which of the following is used to compile Java code?
    a) javac
    b) java
    c) javadoc
    d) jar
    → a) javac

OOPs Concepts

  1. What is inheritance in Java?
    a) Using functions
    b) Creating new classes
    c) Acquiring properties of one class by another
    d) None
    → c) Acquiring properties of one class by another
  2. Which keyword is used to inherit a class?
    a) implement
    b) extends
    c) inherit
    d) interface
    → b) extends
  3. What is polymorphism?
    a) Overloading
    b) Overriding
    c) Both a and b
    d) None
    → c) Both a and b
  4. Which of these is a superclass of all classes in Java?
    a) Object
    b) Class
    c) Parent
    d) Abstract
    → a) Object
  5. What does encapsulation mean?
    a) Binding data and code
    b) Inheritance
    c) Overloading
    d) None
    → a) Binding data and code

Data Types & Operators

  1. Which data type is used to store a single character?
    a) String
    b) char
    c) Character
    d) int
    → b) char
  2. What is the size of an int in Java?
    a) 4 bytes
    b) 2 bytes
    c) 8 bytes
    d) Depends on system
    → a) 4 bytes
  3. Which operator is used for logical AND?
    a) &
    b) &&
    c) |
    d) ||
    → b) &&
  4. Which type is not a primitive type?
    a) int
    b) float
    c) boolean
    d) String
    → d) String
  5. What will be the result of 5/2 in Java?
    a) 2.5
    b) 2
    c) 3
    d) Error
    → b) 2

Control Statements

  1. Which loop is guaranteed to execute at least once?
    a) for
    b) while
    c) do-while
    d) if
    → c) do-while
  2. Which keyword is used to exit a loop?
    a) exit
    b) continue
    c) return
    d) break
    → d) break
  3. What is used to skip current iteration in a loop?
    a) break
    b) return
    c) continue
    d) skip
    → c) continue
  4. Which statement is used for decision-making?
    a) for
    b) if
    c) do
    d) loop
    → b) if
  5. Which is the correct way to declare a switch statement?
    a) switch(){}
    b) switch case
    c) switch(variable){}
    d) if switch
    → c) switch(variable){ }

Exception Handling

  1. Which keyword is used to handle exceptions?
    a) try
    b) throw
    c) catch
    d) All of the above
    → d) All of the above
  2. Which is a checked exception?
    a) ArithmeticException
    b) NullPointerException
    c) IOException
    d) ArrayIndexOutOfBoundsException
    → c) IOException
  3. Which block is always executed?
    a) catch
    b) try
    c) finally
    d) throw
    → c) finally
  4. How to throw an exception manually?
    a) throws
    b) throw
    c) catch
    d) try
    → b) throw
  5. What does throws keyword indicate?
    a) Code execution
    b) Return type
    c) Exception declaration
    d) Loop
    → c) Exception declaration

Classes & Objects

  1. Which keyword is used to create an object?
    a) class
    b) new
    c) object
    d) this
    → b) new
  2. What is a constructor?
    a) A variable
    b) A method
    c) A class
    d) A block to initialize objects
    → d) A block to initialize objects
  3. Which of these is not a valid constructor type?
    a) Default
    b) Static
    c) Parameterized
    d) Copy
    → b) Static
  4. What is this keyword in Java?
    a) Refers to parent object
    b) Refers to current object
    c) Refers to child class
    d) Refers to static context
    → b) Refers to current object
  5. Which block is used for final cleanup of object?
    a) finalize()
    b) cleanup()
    c) destructor()
    d) close()
    → a) finalize()

Inheritance, Interfaces & Abstract Classes

  1. Which keyword is used to implement an interface?
    a) inherit
    b) extends
    c) implements
    d) override
    → c) implements
  2. Can an interface contain constructor?
    a) Yes
    b) No
    → b) No
  3. Can a class extend more than one class?
    a) Yes
    b) No
    → b) No
  4. Can a class implement multiple interfaces?
    a) Yes
    b) No
    → a) Yes
  5. Which is not a type of inheritance in Java?
    a) Single
    b) Hybrid
    c) Multilevel
    d) Multiple using class
    → b) Hybrid

Advanced Java (String, Collections, Threads)

  1. Which is immutable in Java?
    a) String
    b) StringBuilder
    c) Array
    d) Collection
    → a) String
  2. Which method is used to find string length?
    a) size()
    b) getLength()
    c) length()
    d) count()
    → c) length()
  3. Which interface provides dynamic array in Java?
    a) List
    b) Array
    c) Collection
    d) Set
    → a) List
  4. Which class implements List interface?
    a) HashMap
    b) ArrayList
    c) HashSet
    d) Hashtable
    → b) ArrayList
  5. Which collection does not allow duplicates?
    a) List
    b) Set
    c) ArrayList
    d) Map
    → b) Set

Multithreading & Miscellaneous

  1. Which method starts a thread execution?
    a) run()
    b) start()
    c) execute()
    d) init()
    → b) start()
  2. Thread.sleep() pauses thread for:
    a) seconds
    b) milliseconds
    c) microseconds
    d) minutes
    → b) milliseconds
  3. Which interface is used for threads?
    a) Runnable
    b) Threadable
    c) Executable
    d) Callable
    → a) Runnable
  4. Which keyword is used for synchronization?
    a) sync
    b) synchronized
    c) lock
    d) mutex
    → b) synchronized
  5. What is garbage collection in Java?
    a) Memory allocation
    b) Removing unused objects
    c) Cleaning files
    d) Managing exceptions
    → b) Removing unused objects

Java Features & Keywords

  1. Java is a ______ language.
    a) Platform dependent
    b) Platform independent
    c) Machine language
    d) Scripting
    → b) Platform independent
  2. Which memory is used by JVM to store objects?
    a) Stack
    b) Heap
    c) Code
    d) Class
    → b) Heap
  3. Which keyword makes a variable constant?
    a) constant
    b) final
    c) static
    d) const
    → b) final
  4. Which of these is not a Java feature?
    a) Object-oriented
    b) Architecture-neutral
    c) Use of pointers
    d) Robust
    → c) Use of pointers
  5. Which package contains Scanner class?
    a) java.util
    b) java.io
    c) java.lang
    d) java.awt
    → a) java.util

Leave a Reply

Your email address will not be published. Required fields are marked *