0% found this document useful (0 votes)
4 views7 pages

JAVA MCQ Ans19.5

The document is a comprehensive guide covering various aspects of Java programming, including its features, object-oriented programming concepts, exception handling, collections, and JDBC. It contains multiple-choice questions and answers related to Java fundamentals, such as method overloading, data types, exception handling, and the Java Collections Framework. Each unit focuses on different topics, providing a structured approach to learning Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

JAVA MCQ Ans19.5

The document is a comprehensive guide covering various aspects of Java programming, including its features, object-oriented programming concepts, exception handling, collections, and JDBC. It contains multiple-choice questions and answers related to Java fundamentals, such as method overloading, data types, exception handling, and the Java Collections Framework. Each unit focuses on different topics, providing a structured approach to learning Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

UNIT -1

1.​ Who invented Java Programming?​


b) James Gosling

2.​ Which statement is true about Java?​


d) Java is a platform-independent programming language

3.​ Which component is used to compile, debug and execute the Java programs?​
c) JDK

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


b) Use of pointers

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


c) keyword

6.​ Which of the following is not an OOPS concept in Java?​


c) Compilation

7.​ What is not the use of “this” keyword in Java?​


b) Passing itself to the method of the same class​

8.​ What will be the error in the following Java code?

byte b = 50;

b = b * 50;

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

9.​ Which of the following is a type of polymorphism in Java Programming?​


b) Compile time polymorphism

10.​Which of these are selection statements in Java?​


d) if()

11.​Which of these keywords is used to define interfaces in Java?​


c) interface

12.​Which of the following is a superclass of every class in Java?​


c) Object class

13.​Which one of the following is not an access modifier?​


b) Void

14.​What is the numerical range of a char data type in Java?​


c) 0 to 65535
15.​Which of these coding types is used for data type characters in Java?​
c) UNICODE

16.​Which of these packages contains abstract keyword?​


a) java.lang

17.​When is method overloading determined?​


b) At compile time

18.​Which of these values can a boolean variable in Java contain?​


a) True & False

19.​If an expression contains double, int, float, long, then the whole expression will be
promoted into which of these data types?​
c) double

20.​Which of these operators is used to allocate memory to array variable in Java?​


c) new

UNIT – II

1.​ What is the process of defining two or more methods within the same class that
have the same name but different parameters declaration?​
a) method overloading
2.​ Which of these can be overloaded?​
c) All of the mentioned (Methods and Constructors can both be overloaded)
3.​ Which of these is correct about passing an argument by call-by-value process?​
a) Copy of argument is made into the formal parameter of the subroutine
4.​ What is the process of defining a method in terms of itself, that is a method that
calls itself?​
d) Recursion
5.​ Arrays in Java are implemented as?​
b) object
6.​ Which of these keywords is used to prevent content of a variable from being
modified?​
a) final
7.​ Which of these cannot be declared static?​
b) object
8.​ Which of the following statements are incorrect?​
d) when object of class is declared, each object contains its own copy of static
variables​
9.​ Which of the following statements are incorrect?​
b) final variable must be initialized at the time of declaration​

10.​Which of these methods must be made static?​


a) main()
11.​Which among the following best describes a nested class?​
a) Class inside a class
12.​Which feature of OOP reduces the use of nested classes?​
b) Inheritance
13.​How many categories are nested classes divided into?​
a) 2​

14.​Non-static nested classes have access to _____________ from enclosing class.​


d) All the members
15.​Static nested classes don’t have access to _________________ from enclosing
class.​
a) Private members
16.​The nested class can be declared ___________________​
d) Public, Protected, Private or Package private
17.​Use of nested class ____________ encapsulation.​
a) Increases
18.​Which of these is supported by method overriding in Java?​
c) Polymorphism
19.​Which of these keywords is used to define packages in Java?​
c) package
20.​Which of these is a mechanism for naming and visibility control of a class and its
content?​
b) Packages

UNIT- III

1.​ When does Exceptions in Java arise in code sequence?​


a) Run Time
2.​ Which of these keywords is not a part of exception handling?​
c) thrown​

3.​ Which of these keywords must be used to monitor for exceptions?​


a) try
4.​ Which of these keywords must be used to handle the exception thrown by try
block in some rational manner?​
d) catch
5.​ Which of these exceptions handles the situations when an illegal argument is
used to invoke a method?​
c) IllegalArgumentException
6.​ Which of these packages contain all the Java’s built-in exceptions?​
c) java.lang
7.​ Which of these exceptions will be thrown if we use null reference for an
arithmetic operation?​
b) NullPointerException
8.​ Which of these methods of Thread class is used to suspend a thread for a period
of time?​
a) sleep()
9.​ Which function of predefined class Thread is used to check whether current
thread being checked is still running?​
a) isAlive()
10.​What is the priority of the thread in output in the given Java program?

Thread t = Thread.currentThread();
t.setName("New Thread");
System.out.println(t.getName());

c) New Thread

11.​Which of these classes is used to create user-defined exception?​


b) Exception
12.​Which of these methods of Thread class is used to find out the priority given to a
thread?​
c) getPriority()
13.​Which of these type parameters is used for a generic method to return and
accept a number?​
b) N​

14.​Which of these is a correct way of defining generic method?​


a) <T1, T2, …, Tn> name(T1, T2, …, Tn) { /* … */ }
15.​Which of the following allows us to call generic methods as a normal method?​
a) Type Interface
16.​Thread priority in Java is?​
a) Integer
17.​What will happen if two threads of the same priority are called to be processed
simultaneously?​
d) It is dependent on the operating system
18.​Which of these statements is incorrect?​
d) A thread can exist only in two states, running and blocked​

19.​If we try to add Enum constants to a TreeSet, what sorting order will it use?​
a) Sorted in the order of declaration of Enums
20.​Which method returns the elements of Enum class?​
b) getEnumConstants()
UNIT –IV

1.​ Which of these class is superclass of String and StringBuffer class?​


Answer: d) None of the mentioned​

2.​ Which of these operators can be used to concatenate two or more String objects?​
Answer: a) +
3.​ Which of this method of class String is used to obtain a length of String object?​
Answer: d) length()
4.​ Which of these method of class String is used to extract a single character from a
String object?​
Answer: c) charAt()
5.​ Which of these constructors is used to create an empty String object?​
Answer: a) String()
6.​ Which of these is an incorrect statement?​
Answer: d) None of the mentioned​

7.​ Which of these packages contain all the collection classes?​


Answer: b) java.util
8.​ Which of these classes is not part of Java’s collection framework?​
Answer: b) Array​

9.​ Which of this interface is not a part of Java’s collection framework?​


Answer: d) SortedList​

10.​Which of these methods deletes all the elements from invoking collection?​
Answer: a) clear()
11.​What is Collection in Java?​
Answer: a) A group of objects
12.​Which of these stream contains the classes which can work on character stream?​
Answer: c) Character Stream
13.​Which of these class is used to read characters in a file?​
Answer: a) FileReader
14.​Which of these method of FileReader class is used to read characters from a file?​
Answer: a) read()
15.​Which of these class can be used to implement the input stream that uses a
character array as the source?​
Answer: c) CharArrayReader
16.​Which of these classes can return more than one character to be returned to
input stream?​
Answer: a) BufferedReader​

17.​Event class is defined in which of these libraries?​


Answer: d) java.awt.event
18.​Which of these methods can be used to determine the type of event?​
Answer: a) getID()
19.​Which of these class is super class of all the events?​
Answer: a) EventObject
20.​Which of these events will be notified if scroll bar is manipulated?​
Answer: c) AdjustmentEvent
21.​Which of these events will be generated if we close an applet’s window?​
Answer: d) WindowEvent
22.​Which of these packages contains all the event handling interfaces?​
Answer: c) java.awt.event
23.​Which of these interfaces handles the event when a component is added to a
container?​
Answer: b) ContainerListener
24.​Which of these methods will respond when you click any button by mouse?​
Answer: a) mouseClicked()
25.​Which of these methods will be invoked if a character is entered?​
Answer: c) keyTyped()

UNIT – V

1.​ Which of the following contains both date and time?​


c) java.util.Date​

2.​ Which of the following is advantage of using JDBC connection pool?​


d) Better performance​

3.​ Which of the following is advantage of using PreparedStatement in Java?​


c) Prevents SQL injection​

4.​ Which one of the following contains date information?​


a) java.sql.Timestamp​

5.​ What does setAutoCommit(false) do?​


c) does not commit transaction automatically after each query
6.​ Which of the following is used to call stored procedure?​
c) CallableStatement
7.​ Which of the following is used to limit the number of rows returned?​
a) setMaxRows(int i)
8.​ What does JDBC stand for?​
a) Java DataBase Connectivity
9.​ Which package contains the JDBC classes and interfaces?​
c) java.sql
10.​What is the purpose of the DriverManager class in JDBC?​
a) To manage database drivers
11.​How do you load a JDBC driver in Java?​
a) Class.forName("driverClassName")
12.​Which method is used to establish a connection to a database in JDBC?​
a) DriverManager.getConnection()
13.​What is a PreparedStatement in JDBC?​
c) A statement that can be reused with different input values
14.​Which interface is used to execute SQL queries in JDBC?
d) All of the above​

15.​Which method is used to execute a SQL SELECT query in JDBC?​


a) executeQuery()
16.​Which method is used to retrieve data from a ResultSet in JDBC?​
d) All of the above​

17.​Which method is used to commit a transaction in JDBC?​


b) commit()
18.​What does the rollback() method do in JDBC?​
c) It undoes all changes made in the current transaction
19.​Which feature was introduced in JDBC 4.0?​
d) All of the above​

20.​What is the purpose of the isValid() method in JDBC 4.0?​


b) To check if a connection is still valid

You might also like