Home

1000+ Java Programming MCQ for SSC CPO [Solved]

Thursday 9th of March 2023

Sharing is caring

1. What does the following line of code do?
TextField text=new TextField(10);

A. Creates text object that can hold 10 rows of text.
B. Creates text object that can hold 10 columns of text.
C. Creates the object text and initializes it with the value 10.
D. The code is illegal.
Answer : B
2. What is java -g used for?
A. Using the jdb tool
B. Executing a class with optimization turned off
C. To provided information about deprecated methods
D. Non of the above
Answer : B
3. 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
4. The import statement is always the first no comment statement in a Java program files.
A. True
B. False
C.
D.
Answer : B
5. 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
6. 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
7. For all insert, update, delete, query operations on a database, ResultSet object creation is mandatory.
A. True.
B. False.
C.
D.
Answer : B
8. If m and n are int type variables, what will be the result of the expression
'm % n' when m = -14 and n = -3?

A. 4
B. 2
C. -2
D. -4
Answer : C
9. 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
10. What is error in the following class definitions? 
abstract class xy { 
abstract sum(int x, int y) {
}
}

A. class header is not define properly
B. constructor is no defined
C. method is not defined properly
D. no error
Answer : C
11. Declaring a method synchronized guarantees that the deadlock cannot occur.
A. True
B. False
C.
D.
Answer : A
12. 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
13. The programmer must explicitly create the system .in and system .out objects.
A. True
B. False
C.
D.
Answer : B
14. EJBs can be of the following type(s)
None of the above

A. Entity Bean
B. Session Bean
C. Message-driven bean
D. All of the above
Answer : D
15. Which of the following represent legal flow control statements?
A. break;
B. break();
C. continue(inner);
D. all of the above
Answer : A
16. We can add more than one class(es) at the time of compilation Java Beans.
A. True.
B. False.
C.
D.
Answer : A
17. A variable declared inside the for loop control can not be referenced out side the loop.
A. True
B. False
C.
D.
Answer : A
18. Every method of a final in class is implicitly final.
A. True
B. False
C.
D.
Answer : A
19. Which of the following methods can be used to draw the outline of a square?
A. fillRect()
B. drawLine()
C. drawString()
D. all of the above
Answer : B
20. 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
21. Two methods cannot have the same name in Java.
A. True
B. False
C.
D.
Answer : B
22. In order to connect to a database through java program we must create _______-
A. Connection, Statement, ResultSet
B. Connection, ResultSet
C. Statement< ResultSet
D. Connection, Statement
Answer : D
23. Consider the following class definition.
Class Student extends String
{
}
What happens when we try to compile this class?

A. Will not compile because class body is not defined
B. Will not compile because class is not declared public
C. Will compile successfully.
D. Will not compile because String is abstract
Answer : D
24. The break statement is required in the default case of a switch selection structure.
A. True
B. False
C.
D.
Answer : B
25. 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
26. To delete a file, we can use an instance of class file.
A. True
B. False
C.
D.
Answer : A
27. The setBackground() method is part of the class
A. Applet
B. Component
C. Container
D. Object
Answer : B
28. Message-Driven beans act as a listener for the Java Message Service API, processing messages synchronously
A. True
B. False
C.
D.
Answer : B
29. Which of the following are not keywords?
A. NULL
B. Implements
C. Protected
D. None of the above
Answer : A
30. Which of the following methods belong to the String class?
A. length()
B. compareTo()
C. substring()
D. all of the them
Answer : D
31. Declarations can appear anywhere in the body of a Java method.
A. True
B. False
C.
D.
Answer : A
32. In a single Servlet class we can use____________
A. doGet(...) method only
B. doPost(...) method only
C. doGet(...) method and doPost(...) method both at a time.
D. Either 'a' or 'b'
Answer : C
33. The keywords reserved but not used in the initial version of Java re:
A. Synchronized
B. Boolean
C. union
D. goto
Answer : D
34. Which of the following will produce a value of 10 if x = 9.7?
A. floor(x)
B. abs(x)
C. rint(x)
D. round(x)
Answer : D
35. DataInput is
A. An abstract class defined is java.io.
B. A class we can use to read primitive data types.
C. An interface that defines methods to open files.
D. An interface that defines methods to read primitive data types.
Answer : D
36. A package is a collection of
A. classes
B. interface
C. editing tools
D. classes and interfaces
Answer : D
37. When we invoke repaint () for a Component, the AWT invokes the method:
A. draw()
B. update()
C. show()
D. paint()
Answer : B
38. Given the code
String s = new String("abc");
Which of the following calls are valid?

A. s.toUpperCase()
B. s.append("xyz")
C. s.setCharAt(1<'A')
D. all of the above
Answer : A
39. Any method in a supper class can be over ridden in its subclass.
A. True
B. False
C.
D.
Answer : B
40. The expression (x == y && a<b) is true If either x == y is true or a<b is true.
A. True
B. False
C.
D.
Answer : B
41. In RMI we invoke client method from remote server
A. True
B. False
C.
D.
Answer : B
42. When we implement an interface method, it should be declared as public.
A. True
B. False
C.
D.
Answer : A
43. Which of the following control expressions are valid for an if statement?
A. an integer expression
B. a Boolean expression
C. either A or B
D. Neither A or B
Answer : B
44. Which of the following statements are valid array declarations?
A. int number();
B. float average[];
C. double[] marks;
D. counter int[];
Answer : B
45. Which are the valid ways to create DataInputStream streams?
A. new DataInputStream(new File("in.dat"));
B. new DataInputStream(new FileInputStream("in.dat"));
C. new DataInputStream("in.dat");
D. new DataInputStream("in.data","r");
Answer : B
46. The name of a Java program file must match the name of the class with the extension Java.
A. True
B. False
C.
D.
Answer : A
47. With javadoc, which of the following denotes a javadoc comment?
A. //#
B. /*
C. /**
D. //**
Answer : C
48. When the string objects are compared with ==, the result is true If the strings contain the same values.
A. True
B. False
C.
D.
Answer : B
49. 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
50. A class may be both abstract and final.
A. True
B. False
C.
D.
Answer : B

Sharing is caring