- What is Java?
- A) A scripting language
- B) An operating system
- C) A programming language
- D) A database management system
- Answer: C) A programming language
- Which of the following is a platform-independent programming language?
- A) C++
- B) Java
- C) Python
- D) Ruby
- Answer: B) Java
- What is the main advantage of Java over other programming languages?
- A) Portability
- B) Speed
- C) Complexity
- D) Syntax
- Answer: A) Portability
- Which of the following is a correct statement about Java?
- A) Java is a purely procedural language
- B) Java supports multiple inheritance
- C) Java programs are compiled into machine code
- D) Java does not support multithreading
- Answer: B) Java supports multiple inheritance
- What is the entry point for a Java program?
- A) main()
- B) start()
- C) run()
- D) begin()
- Answer: A) main()
- Which keyword is used to define a class in Java?
- A) class
- B) struct
- C) define
- D) type
- Answer: A) class
- What is the output of
System.out.println(10 / 3)
?
- A) 3.333
- B) 3
- C) 4
- D) 3.0
- Answer: B) 3
- Which of the following is not a valid Java identifier?
- A) _variableName
- B) variableName1
- C) 1variableName
- D) variableName_
- Answer: C) 1variableName
- What is the default value of an instance variable in Java?
- A) 0
- B) 1
- C) null
- D) undefined
- Answer: C) null
- What is the output of
System.out.println("5" + 3)
?- A) 8
- B) 53
- C) 5 + 3
- D) Error
- Answer: B) 53
- Which of the following is used to read input from the user in Java?
- A) System.out
- B) System.in
- C) System.err
- D) Console
- Answer: B) System.in
- What is the output of
System.out.println(5 == 5.0)
?- A) True
- B) False
- C) Error
- D) None
- Answer: A) True
- What does the
break
statement do in Java?- A) Exits the current loop or switch statement
- B) Continues to the next iteration of a loop
- C) Jumps to a specific label in the code
- D) Terminates the program
- Answer: A) Exits the current loop or switch statement
- Which of the following is true about Java arrays?
- A) Arrays can have a fixed size
- B) Arrays can store elements of different data types
- C) Arrays can dynamically resize themselves
- D) Arrays can only store primitive data types
- Answer: A) Arrays can have a fixed size
- What is the output of
System.out.println("Java".length())
?- A) 4
- B) 5
- C) J
- D) Error
- Answer: A) 4
- Which of the following is not a valid access modifier in Java?
- A) private
- B) protected
- C) default
- D) public
- Answer: C) default
- What does the
finally
block do in Java exception handling?- A) Executes if an exception is caught
- B) Executes regardless of whether an exception is caught
- C) Executes if an exception is not caught
- D) Terminates the program
- Answer: B) Executes regardless of whether an exception is caught
- What is the output of
System.out.println(Math.floor(2.5))
?- A) 2.5
- B) 2
- C) 3
- D) Error
- Answer: B) 2
- Which of the following is true about method overloading in Java?
- A) Methods must have the same name and return type
- B) Methods must have different names and return types
- C) Methods must have the same name but can have different parameters
- D) Methods must have the same parameters but can have different names
- Answer: C) Methods must have the same name but can have different parameters
- What is the output of
System.out.println("Java".substring(1, 3))
?- A) J
- B) av
- C) ava
- D) Error
- Answer: C) ava
- Which of the following is not a valid Java keyword?
- A) final
- B) class
- C) function
- D) static
- Answer: C) function
- What is the output of
System.out.println("Java".charAt(2))
?- A) J
- B) a
- C) v
- D) Error
- Answer: C) v
- What does the
static
keyword do in Java?- A) Indicates that a variable or method belongs to the class, not instances of the class
- B) Indicates that a variable or method can only be accessed by other classes in the same package
- C) Indicates that a variable or method can only be accessed within the same class
- D) Indicates that a variable or method cannot be modified
- Answer: A) Indicates that a variable or method belongs to the class, not instances of the class
- What is the output of
System.out.println("Java".indexOf('a'))
?- A) 0
- B) 1
- C) 2
- D) Error
- Answer: B) 1
- Which of the following statements is true about Java interfaces?
- A) Interfaces can have constructors
- B) Interfaces can have instance variables
- C) A class can implement multiple interfaces
- D) Interfaces can have method implementations
- Answer: C) A class can implement multiple interfaces
- What is the output of
System.out.println("Java".replace('a', 'i'))
? – A) Java B) Jiva- C) Jivi
- D) Error
- Answer: C) Jivi
- What is the output of
System.out.println("Java".toUpperCase())
?- A) Java
- B) JAVA
- C) java
- D) Error
- Answer: B) JAVA
- Which of the following is not a valid Java data type?
- A) int
- B) float
- C) string
- D) double
- Answer: C) string
- What is the output of
System.out.println("Java".equals("java"))
?- A) True
- B) False
- C) Error
- D) None
- Answer: B) False
- Which of the following is true about Java packages?
- A) A package can contain multiple classes
- B) A class can belong to multiple packages
- C) Packages must be imported explicitly to use their classes
- D) All of the above
- Answer: A) A package can contain multiple classes
- What is the output of
System.out.println(Math.round(2.5))
?- A) 2.5
- B) 2
- C) 3
- D) Error
- Answer: C) 3
- Which of the following is a correct way to declare a constant in Java?
- A) final int PI = 3.14;
- B) const int PI = 3.14;
- C) static final int PI = 3.14;
- D) final static int PI = 3.14;
- Answer: D) final static int PI = 3.14;
- What is the output of
System.out.println("Java".startsWith("Ja"))
?- A) True
- B) False
- C) Error
- D) None
- Answer: A) True
- What is the output of
System.out.println("Java".toLowerCase())
?- A) Java
- B) JAVA
- C) java
- D) Error
- Answer: C) java
- Which of the following is not a valid Java control statement?
- A) if-else
- B) switch-case
- C) do-while
- D) for-each
- Answer: D) for-each
- What is the output of
System.out.println(Math.abs(-5))
?- A) -5
- B) 5
- C) -1
- D) 1
- Answer: B) 5
- What is the output of
System.out.println("Java".endsWith("va"))
?- A) True
- B) False
- C) Error
- D) None
- Answer: A) True
- Which of the following is true about Java constructors?
- A) A constructor can return a value
- B) A class can have multiple constructors with different parameter lists
- C) Constructors can be inherited
- D) Constructors can have a return type
- Answer: B) A class can have multiple constructors with different parameter lists
- What is the output of
System.out.println(Math.min(5, 10))
?- A) 5
- B) 10
- C) 0
- D) 1
- Answer: A) 5
- What is the output of
System.out.println("Java".compareTo("java"))
?- A) 0
- B) 1
- C) -1
- D) Error
- Answer: C) -1
- What is the output of
System.out.println(10 % 3)
?- A) 3.333
- B) 3
- C) 1
- D) 0
- Answer: C) 1
- Which of the following is not a valid Java loop?
- A) while
- B) loop
- C) for
- D) do-while
- Answer: B) loop
- What is the output of
System.out.println("Java".substring(2))
?- A) J
- B) av
- C) va
- D) Error
- Answer: C) va
- What is the output of
System.out.println(Math.pow(2, 3))
?- A) 2
- B) 3
- C) 8
- D) 6
- Answer: C) 8
- Which of the following is true about Java threads?
- A) A thread can be restarted once it is stopped
- B) Threads share the same memory space
- C) A thread can only be created by extending the Thread class
- D) Threads cannot be synchronized
- Answer: B) Threads share the same memory space
- What is the output of
System.out.println("Java".indexOf('v', 2))
?- A) 0
- B) 1
- C) 2
- D) Error
- Answer: C) 2
- What is the output of
System.out.println("Java".isEmpty())
?- A) True
- B) False
- C) Error
- D) None
- Answer: B) False
- Which of the following is a correct way to handle exceptions in Java?
- A) try-catch
- B) try-except
- C) catch-throw
- D) throw-try
- Answer: A) try-catch
- What is the output of
System.out.println(Math.sqrt(25))
?- A) 5
- B) 25
- C) 2
- D) Error
- Answer: A) 5
- Which of the following is true about Java inheritance?
- A) A class can inherit from multiple classes
- B) A class can inherit from both a class and an interface
- C) A class can inherit from only one class
- D) All of the above
- Answer: C) A class can inherit from only one class
- What is the output of
System.out.println("Java".replace("a", "i"))
?- A) Java
- B) Jiva
- C) Jivi
- D) Error
- Answer: C) Jivi
- Which of the following is not a valid Java access modifier?
- A) public
- B) private
- C) protected
- D) package
- Answer: D) package
53
. What is the output of System.out.println("Java".toLowerCase())
?
– A) Java
– B) JAVA
– C) java
– D) Error
– Answer: C) java
- What is the output of
System.out.println(Math.ceil(2.5))
?- A) 2.5
- B) 2
- C) 3
- D) Error
- Answer: C) 3
- Which of the following is true about Java generics?
- A) Generics allow the use of parameterized types
- B) Generics are only used for collections
- C) Generics cannot be used with classes
- D) Generics cannot be used with methods
- Answer: A) Generics allow the use of parameterized types
- What is the output of
System.out.println("Java".substring(1, 3))
?- A) J
- B) av
- C) ava
- D) Error
- Answer: C) ava
- What is the output of
System.out.println("Java".lastIndexOf('a'))
?- A) 0
- B) 1
- C) 2
- D) Error
- Answer: C) 2
- Which of the following is true about Java interfaces?
- A) Interfaces can have constructors
- B) Interfaces can have instance variables
- C) A class can implement multiple interfaces
- D) Interfaces can have method implementations
- Answer: C) A class can implement multiple interfaces
- What is the output of
System.out.println(Math.max(5, 10))
?- A) 5
- B) 10
- C) 0
- D) 1
- Answer: B) 10
- What is the output of
System.out.println("Java".compareToIgnoreCase("java"))
?- A) 0
- B) 1
- C) -1
- D) Error
- Answer: A) 0
- Which of the following is not a valid Java data type?
- A) int
- B) float
- C) string
- D) double
- Answer: C) string
- What is the output of
System.out.println("Java".endsWith("va"))
?- A) True
- B) False
- C) Error
- D) None
- Answer: A) True
- What is the output of
System.out.println(Math.random())
?- A) Random number between 0 and 1
- B) 0
- C) 1
- D) Error
- Answer: A) Random number between 0 and 1
- Which of the following is true about Java constructors?
- A) A constructor can return a value
- B) A class can have multiple constructors with different parameter lists
- C) Constructors can be inherited
- D) Constructors can have a return type
- Answer: B) A class can have multiple constructors with different parameter lists
- What is the output of
System.out.println("Java".compareTo("Java"))
?- A) 0
- B) 1
- C) -1
- D) Error
- Answer: A) 0
- What is the output of
System.out.println("Java".concat(" is awesome"))
?- A) Java
- B) Java is awesome
- C) Error
- D) None
- Answer: B) Java is awesome
- Which of the following is true about Java arrays?
- A) Arrays can have a fixed size
- B) Arrays can store elements of different data types
- C) Arrays can dynamically resize themselves
- D) Arrays can only store primitive data types
- Answer: A) Arrays can have a fixed size
- What is the output of
System.out.println(Math.ceil(2.5))
?- A) 2.5
- B) 2
- C) 3
- D) Error
- Answer: C) 3
- What is the output of
System.out.println("Java".replace("a", "i"))
?- A) Java
- B) Jiva
- C) Jivi
- D) Error
- Answer: C) Jivi
- Which of the following is true about Java threads?
- A) A thread can be restarted once it is stopped
- B) Threads share the same memory space
- C) A thread can only be created by extending the Thread class
- D) Threads cannot be synchronized
- Answer: B) Threads share the same memory space
- What is the output of
System.out.println("Java".substring(1, 3))
?- A) J
- B) av
- C) ava
- D) Error
- Answer: C) ava
- What is the output of
System.out.println("Java".startsWith("Ja"))
?- A) True
- B) False
- C) Error
- D) None
- Answer: A) True
- Which of the following is true about Java inheritance?
- A) A class can inherit from multiple classes
- B) A class can inherit from both a class and an interface
- C) A class can inherit from only one class
- D) All of the above
- Answer: C) A
- What is the output of
System.out.println("Java".equals("java"))
?- A) True
- B) False
- C) Error
- D) None
- Answer: B) False
- What is the output of
System.out.println("Java".toLowerCase())
?- A) Java
- B) JAVA
- C) java
- D) Error
- Answer: C) java
- Which of the following is true about Java generics?
- A) Generics allow the use of parameterized types
- B) Generics are only used for collections
- C) Generics cannot be used with classes
- D) Generics cannot be used with methods
- Answer: A) Generics allow the use of parameterized types
- What is the output of
System.out.println("Java".substring(2))
?- A) J
- B) av
- C) va
- D) Error
- Answer: C) va
- What is the output of
System.out.println("Java".indexOf('v', 2))
?- A) 0
- B) 1
- C) 2
- D) Error
- Answer: C) 2
- What is the output of
System.out.println("Java".lastIndexOf('a'))
?- A) 0
- B) 1
- C) 2
- D) Error
- Answer: C) 2
- What is the output of
System.out.println("Java".compareToIgnoreCase("java"))
?- A) 0
- B) 1
- C) -1
- D) Error
- Answer: A) 0
- What is the output of
System.out.println(Math.random())
?- A) Random number between 0 and 1
- B) 0
- C) 1
- D) Error
- Answer: A) Random number between 0 and 1
- What is the output of
System.out.println("Java".concat(" is awesome"))
?- A) Java
- B) Java is awesome
- C) Error
- D) None
- Answer: B) Java is awesome
- What is the output of
System.out.println("Java".compareTo("Java"))
?- A) 0
- B) 1
- C) -1
- D) Error
- Answer: A) 0
- What is the output of
System.out.println(Math.min(5, 10))
?- A) 5
- B) 10
- C) 0
- D) 1
- Answer: A) 5
- Which of the following is not a valid Java loop?
- A) while
- B) loop
- C) for
- D) do-while
- Answer: B) loop
- What is the output of
System.out.println("Java".endsWith("va"))
?- A) True
- B) False
- C) Error
- D) None
- Answer: A) True
- What is the output of
System.out.println(Math.sqrt(25))
?- A) 5
- B) 25
- C) 2
- D) Error
- Answer: A) 5
- Which of the following is true about Java threads?
- A) A thread can be restarted once it is stopped
- B) Threads share the same memory space
- C) A thread can only be created by extending the Thread class
- D) Threads cannot be synchronized
- Answer: B) Threads share the same memory space
- What is the output of
System.out.println("Java".substring(1, 3))
?- A) J
- B) av
- C) ava
- D) Error
- Answer: C) ava
- What is the output of
System.out.println("Java".startsWith("Ja"))
?- A) True
- B) False
- C) Error
- D) None
- Answer: A) True
- Which of the following is true about Java inheritance?
- A) A class can inherit from multiple classes
- B) A class can inherit from both a class and an interface
- C) A class can inherit from only one class
- D) All of the above
- Answer: C) A class can inherit from only one class
- What is the output of
System.out.println("Java".equals("java"))
?- A) True
- B) False
- C) Error
- D) None
- Answer: B) False
- What is the output of
System.out.println("Java".toLowerCase())
?- A) Java
- B) JAVA
- C) java
- D) Error
- Answer: C) java
- Which of the following is true about Java generics?
- A) Generics allow the use of parameterized types
- B) Generics are only used for collections
- C) Generics cannot be used with classes
- D) Generics cannot be used with methods
- Answer: A) Generics allow the use of parameterized types
- What is the output of
System.out.println("Java".substring(2))
?- A) J
- B) av
- C) va
- D) Error
- Answer: C) va
- What is the output of
System.out.println("Java".indexOf('v', 2))
?- A) 0
- B) 1
- C) 2
- D) Error
- Answer: C) 2
- What is the output of
System.out.println("Java".lastIndexOf('a'))
?- A) 0
- B) 1
- C) 2
- D) Error
- Answer: C) 2
- What is the output of
System.out.println("Java".compareToIgnoreCase("java"))
?- A) 0
- B) 1
- C) -1
- D) Error
- Answer: A) 0
- What is the output of
System.out.println(Math.random())
?- A) Random number between 0 and 1
- B) 0
- C) 1
- D) Error
- Answer: A) Random number between 0 and 1
- What is the output of