0% found this document useful (0 votes)
48 views

Java Mcqs

The document discusses Java concepts related to access specifiers, packages, exceptions, threads, and file I/O. It contains questions and answers related to these topics. Access specifiers control visibility and inheritance. Packages provide namespaces and access control for classes. Exceptions handle errors during runtime. Threads allow concurrent execution. File I/O involves reading and writing files using streams.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Java Mcqs

The document discusses Java concepts related to access specifiers, packages, exceptions, threads, and file I/O. It contains questions and answers related to these topics. Access specifiers control visibility and inheritance. Packages provide namespaces and access control for classes. Exceptions handle errors during runtime. Threads allow concurrent execution. File I/O involves reading and writing files using streams.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

UNIT 3

1. Which of these access specifiers must be used for main() method?


a) private b) public c) protected d) None of the mentioned
2. Which of these is used to access member of class before object of that class is created?
a) public b) private c) static d) protected
3. Which of these is used as default for a member of a class if no access specifier is used for it?
a) private b) public c) public, within its own package d) protected
4. What is the process by which we can control what parts of a program can access the members of a
class?
a) Polymorphism b) Abstraction c) Encapsulation d) Recursion
5. Which of these keywords is used to define packages in Java?
a) pkg b) Pkg c) package d) Package
6. Which of these is a mechanism for naming and visibility control of a class and its content?
a) Object b) Packages c) Interfaces d) None of the Mentioned.
7. Which of the following is correct way of importing an entire package ‘pkg’?
a) import pkg. b) Import pkg. c) import pkg.* d) Import pkg.*
8. Which of the following is incorrect statement about packages?
a) Package defines a namespace in which classes are stored.
b) A package can contain other package within it.
c) Java uses file system directories to store packages.
d) A package can be renamed without renaming the directory
9. Which of the following package stores all the standard java classes?
a) lang b) java c) utiL d) java.packages
10. Which of these access specifiers can be used for an interface?
a) Public b) Protected c) private d) All of the mentioned
11. Which of these keywords is used by a class to use an interface defined previously?
a) import b) Import c) implements d) Implements
12. . Which of the following is incorrect statement about packages?
a) Interfaces specifies what class must do but not how it does.
b) Interfaces are specified public if they are to be accessed by any code in the program.
c) All variables in interface are implicitly final and static.
d) All variables are static and methods are public if interface is defined pubic.
13. What is the process of defining more than one method in a class differentiated by parameters?
a) Function overriding b) Function overloading c) Function doubling d) None of these
14. Which of these keywords are used to define an abstract class?
a) abst b) abstract c) Abstract d) abstract clas
15. Which one of the following is not an access modifier
a. public b. private. C. protected d. void
16. All methods must be implemented of an interface.
A. True B. False
17. What does an interface contain?
A. Method definitionB. Method declaration C. Method declaration and definition D. none
18. Which of these access specifiers can be used for an interface?
a) Public b) Protected c) private d) All of the mentioned

488
UNIT 4
1. An instance of are unchecked exceptions
2. An application responds to an exception by throwing an another exception is called as
.
3. Benifits of exception handling
a.Separating Error-Handling code from “regular”
business logic codeb.Propagating errors up the call
stack
c.Grouping and
differentiating error types
d.none
4. A thread can acquire a lock by using which reserved keyword
a. volatile b. synchronized c. locked d. none

5. All exceptions are sub-classes of the build-in class


a. Throwable b.serializable c. exception d.none
6. defined automatically for user programs to include: division by
zero, invalid arrayindexing, etc.
7. is the most general and represents any type of error that can occur
when performing

9.Sleep(10000) causes the main thread to sleep for seconds

10. Which method on a condition should you invoke to wake all waiting thread?
a) condition.wake(); b) condition.signal();
c) condition.wakeAll(); d) condition.signalAll();

11.You can use the method to force


one thread to wait for another thread
a) sleep(long milliseconds) b) yield() c) stop() d) join()
488
12.Which cannot directly cause a thread to stop executing?
a) Calling a yield method b) Calling the start method on another thread object
c) Calling the notify method on object d) Calling wait method on an object

13. Thread code is written in ___________ method

14. A thread is a

A) light B) strong C) small D) large

15.This thread is called the thread because it is the thread that executes when you start the main
program.
A) float B) main C) void D) int

16. Random class belongs to package


a. java.io b. java.util c. java.lang d. java.awt

17. When does Exceptions in Java arises in code sequence?


a) Run Time b) Compilation Time c) Can Occur Any Time d) None of the mentioned
18. Which of these keywords is not a part of exception handling?
a) try b) finally c) thrown d) catch
19. Which of these is a super class of all exceptional type classes?
a) String
b) RuntimeExceptions
c) Throwable
d) Cachable

20. Which of these class is related to all the exceptions that cannot be caught?
a) Error
b) Exception
c) RuntimeExecption
d) All of the mentioned
21. Mutual exclusion of shared resource between threads is achieved with _________keyword

488
22. Which of these handles the exception when no catch is used?
a) Default handler
b) finally
c) throw handler
d) Java run time system

23. Which of these keywords is used to manually throw an exception?


a) try
b) finally
c) throw
d) catch

24. Which of these class is related to all the exceptions that are explicitly thrown?
a) Error
b) Exception
c) Throwable
d) Throw

25. You can use the __________ method to force one thread to wait for another thread to
Finish
sleep(long milliseconds) b. yield() c. stop() d. join()
25. A thread can acquire a lock by using which reserved keyword
A. volatile B. synchronized C. locked D.
none
26. How many threads can a process contain
A. 1 B.2 C. multiple D. none
27. Two types of streams in java are _______________ and _______________
28. A Java exception is an instance of ____________ _ . [ ]
a. Runtime Exception b. Exception c. Error d. Throw able
29. Program statements that are to be monitored for exceptions are contained within block.[
]
a. try b. catch c. throw d. throws
30. modifier can be accessed only to classes in the same package.

31. User exception can be created by inheriting


a . thread b. package c. Exception d. Runnable
488
UNIT 5

1. Which of these class contains the methods used to write in a file?


a) FileStream
b) FileInputStream
c) BUfferedOutputStream
d) FileBufferStream

2. Which of these exception is thrown in cases when the file specified for writing it not
found?
a) IOException
b) FileException
c) FileNotFoundException
d) FileInputException

3. Which of these values is returned by read() method is end of file (EOF) is encountered?
a) 0
b) 1
c) -1
d) Null

4. Which of these exception is thrown by close() and read() methods?


a) IOException
b) FileException
c) FileNotFoundException
d) FileInputOutputException

5. Which of these methods is used to write() into a file?


a) put()
b) putFile()
488
c) write()
d) writeFile()

6. . Which of these packages contain classes and interfaces used for input &
output operationsof a program?
a) java.util
b) java.lang
c) java.io
d) All of the mentioned

7. Which of these class is not a member class of java.io package?


a) String
b) StringReader
c) Writer
d) File
.
8. Which of these interface is not a member of java.io package?
a) DataInput
b) ObjectInput
c) ObjectFilter
d) FileFilter

9. Which of these class is not related to input and output stream in terms of functioning?
a) File
b) Writer
c) InputStream
d) Reader

10. Which of these is specified by a File object?


a) a file in disk
b) directory path
c) directory in disk
488
d) None of the mentioned

11. Which of these is method for testing whether the specified element is a file or a
directory?
a) IsFile()
b) isFile()
c) Isfile()
d) isfile()

12 Which of these method of InputStream is used to read integer


representation of nextavailable byte input?
a) read()
b) scanf()
c) get()
d) getInteger()

13. Which of these data type is returned by every method of OutputStream?


a) int
b) float
c) byte
d) None of the mentioned

14. Which of these is a method to clear all the data present in output buffers?
a) clear()
b) flush()
c) fflush()
d) close()
.
15. Which of these is method is used for writing bytes to an outputstream?
a) put()
b) print()
488
c) printf()
d) write()

16. In jdbc, type 4 driver is also called _____________


17. No. of Types of java database connection drivers
a. 2 b.4 c. 6 d.8
18. Which of the following type of JDBC driver, uses database native protocol?
a - JDBC-ODBC Bridge plus ODBC driver
b - Native-API, partly Java driver
c- JDBC-Net, pure Java driver
d - Native-protocol, pure Java driver

488
16. Which of these method of FileReader class is used to read characters from a file?
a) read()
b) scanf()
c) get()
d) getInteger()

17. Which of these class can be used to implement input stream that uses a character array as
the source?
a) BufferedReader
b) FileReader
c) CharArrayReader
d) FileArrayReader

18.Which of these is a method to clear all the data present in output buffers?
a) clear()
b) flush()
c) fflush()
d) close()
19. Non recoverable exceptions belongs to the class
a. Error b. Exception
c. IllegalException d. ClassNotFoundException

20 Which of these classes can return more than one character to be returned to input stream?
a) BufferedReader
b) Bufferedwriter
c) PushbachReader
d) CharArrayReader

21. Which of these class is used to read and write bytes in a file
a.. FileReader b. FileWriter c.FileInputStream d.RandomAccessFile
22. In jdbc network protocol driver ______________interface is used to connect to database

You might also like