Home

1000+ Java Programming MCQ for UPSC CSE [Solved]

Thursday 9th of March 2023

Sharing is caring

1. A catch can have comma-separated multiple arguments.
A. True
B. False
C.
D.
Answer : B
2. The keywords reserved but not used in the initial version of Java re:
A. Synchronized
B. Boolean
C. union
D. goto
Answer : D
3. putValue(...) method takes _____________________-
A. Two arguments of object type
B. First one is of a character type and second one is of an object type
C. First one is of an object type and second one is of a character type
D. None of the above.
Answer : A
4. Which key word can protect a class in package from accessibility by the classes outside the package?
A. private
B. protected
C. final
D. don't use any keyword at all(make it default)
Answer : D
5. In RMI we invoke client method from remote server
A. True
B. False
C.
D.
Answer : B
6. When X is a positive number the operations x>> 2 and x>>>2 both produce the same result.
A. True
B. False
C.
D.
Answer : A
7. Any class may be inherited by another class in the same package.
A. True
B. False
C.
D.
Answer : B
8. Frames and applets cannot be used together in the same program.
A. True
B. False
C.
D.
Answer : B
9. Java always provides a default constructor to a class.
A. True
B. False
C.
D.
Answer : B
10. What is wrong in the following class definitions? 
abstract class print { 
abstract show();
}
class Display extends print {
}

A. Nothing is wrong
B. Wrong Method show() should have a return type
C. Wrong Methods show() is not implemented in Display
D. Wrong Display does not contain any members.
Answer : C
11. class.forName(...) creates an instance of java ODBC driver
A. True
B. False
C.
D.
Answer : A
12. When we invoke repaint () for a Component, the AWT invokes the method:
A. draw()
B. update()
C. show()
D. paint()
Answer : B
13. Which of the following represent legal flow control statements?
A. break();
B. continue(inner);
C. return;
D. exit();
Answer : C
14. When present, package must be the first no comment statement in the file.
A. True
B. False
C.
D.
Answer : A
15. Which of the following statements are true?
A. UTF characters are all 24 bits.
B. Reader class has methods that can read integers and floats.
C. Unicode characters are all 16 bits.
D. all of the above
Answer : C
16. Consider the following class definitions:
 class maths { 
student student1;
}
class student {
String name;
}

This code represents:


A. an 'is a' relationship
B. a 'has a' relationship
C. both
D. neither
Answer : B
17. An EJB is a server-side component that encapsulates the business logic of an application
A. True
B. False
C.
D.
Answer : A
18. A Java monitor must either extend thread class or implement Runnable interface.
A. True
B. False
C.
D.
Answer : B
19. Session bean
A. Represents a single client inside the application server
B. Can not be shared
C. Is not persistent
D. Satisfies all of the above conditions
Answer : D
20. Which of the following statements are valid array declarations?
A. int number();
B. float average[];
C. double[] marks;
D. counter int[];
Answer : B
21. Which of the following methods can be used to remove a component from the display?
A. remove()
B. desappear()
C. hide()
D. move()
Answer : C
22. The setBackground() method is part of the class
A. Applet
B. Component
C. Container
D. Object
Answer : B
23. JdbcOdbcDriver is an object of Object class
A. True
B. False
C.
D.
Answer : B
24. It is an error to catch the same type of exception in two different catch blocks associated with a particular try block.
A. True
B. False
C.
D.
Answer : A
25. The modulus operator (%) can be used only with Integer operands.
A. True
B. False
C.
D.
Answer : B
26. Declaring a method synchronized guarantees that the deadlock cannot occur.
A. True
B. False
C.
D.
Answer : A
27. Every call to wait has a corresponding call to notify that will eventually end the wafting.
A. True
B. False
C.
D.
Answer : A
28. Which of the following classes are available in the java.lang package?
A. Random
B. Stack
C. String Buffer
D. Vector
Answer : A
29. Declarations can appear anywhere in the body of a Java method.
A. True
B. False
C.
D.
Answer : A
30. Consider the following statements:
int x = 10, y = 15; 
x = ((x < y) ? (y + x) : (y - x);

What will be the value of x after executing these statements?

A. 25
B. 15
C. 5
D. Error can't be executed.
Answer : A
31. Which of the following methods belong to the String class?
A. length()
B. compareTo()
C. substring()
D. all of the them
Answer : D
32. It is an error to have a method with the same signature in both the super class and its subclass.
A. True
B. False
C.
D.
Answer : B
33. Which of the following command lines options generates documentation for all classes and methods?
A. -protected
B. -public
C. -private
D. -encoding
Answer : C
34. Connection, Statement are interfaces and ResultSet is a class.
A. True.
B. False.
C.
D.
Answer : B
35. A final class may not have any abstract method.
A. True
B. False
C.
D.
Answer : A
36. A class may be both abstract and final.
A. True
B. False
C.
D.
Answer : B
37. Which of the following string can be used as mode string for creating a RandomAccessFile object?
A. "rw"
B. "wr"
C. "0"
D. 'w''
Answer : A
38. executeUpdate(------------) returns ___________
A. Nothing
B. Returns a ResultSet object
C. Returns an integer value to show the no. of updated rows
D. None of the above.
Answer : C
39. Give file is a file object, which of the following are legal statements to create a new file.
A. file.create();
B. FileOutputStream fos=new FileOutputStream(file);
C. FileInputStream fis=new FileInputStream(file);
D. all of the above
Answer : B
40. Members of a class specified as private are accessible only to the methods of the class.
A. True
B. False
C.
D.
Answer : A
41. A panel can not be added to another panel.
A. True
B. False
C.
D.
Answer : B
42. Which of the following will produce a value of 22 if x=22.9:
A. Ceil(x)
B. Round(x)
C. Rint(x)
D. Abs(x)
Answer : C
43. Any method in a supper class can be over ridden in its subclass.
A. True
B. False
C.
D.
Answer : B
44. The import statement is always the first no comment statement in a Java program files.
A. True
B. False
C.
D.
Answer : B
45. Which of the following keywords are used to control access to a class member?
A. default
B. protected
C. interface
D. None of the above
Answer : B
46. When we implement the Runnable interface, we must define the method
A. start()
B. init()
C. runnable()
D. run()
Answer : D
47. In evaluating a logical expression of type 'Boolean expression 1&& Boolean expression 2', both the Boolean expressions are not always evaluated.
A. True
B. False
C.
D.
Answer : A
48. If you want to assign a value of 99 to the variable year, then which of the following lines can be used within an <applet> tags?
A. number=getParameter(99)
B. <number==99>
C. D. <param = radius value ==99>
Answer : C
49. The default case is always required in the switch selection structure.
A. True
B. False
C.
D.
Answer : B
50. Every method of a final in class is implicitly final.
A. True
B. False
C.
D.
Answer : A

Sharing is caring