Home

1000+ Java Programming MCQ for XAT [Solved]

Thursday 9th of March 2023

Sharing is caring

1. Any method in a supper class can be over ridden in its subclass.
A. True
B. False
C.
D.
Answer : B
2. 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
3. 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
4. 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
5. It is perfectly legal to refer to any instance variable inside of a static method.
A. True
B. False
C.
D.
Answer : B
6. executeUpdate automatically updates data because___________
A. auto commit is on, by default
B. It performs a hidden commit statement as well
C. Does not commit
D. None of the above.
Answer : A
7. 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
8. A JSP file can be stored_________________
A. With the extension .jsp in servlets folder of the jws
B. With the extension .html in public_html folder of the jws
C. With the extension .jsp in public_html folder of the jws
D. None of the above.
Answer : C
9. 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
10. We can over load methods with differences only in their return type.
A. True
B. False
C.
D.
Answer : B
11. The concept of multiple inheritance is implemented in Java by
A. extending two or more classes
B. extending one class and implementing one or more interfaces
C. all the above
D.
Answer : B
12. Submit button always fires doPost(...)
A. True
B. False
C.
D.
Answer : B
13. When present, package must be the first no comment statement in the file.
A. True
B. False
C.
D.
Answer : A
14. 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
15. A method declared as static can not access non-static class members.
A. True
B. False
C.
D.
Answer : A
16. It is an error if a class with one or more abstract methods is not explicitly declared abstract.
A. True
B. False
C.
D.
Answer : A
17. Which of the following command lines options generates documentation for all classes and methods?
A. -protected
B. -public
C. -private
D. -encoding
Answer : C
18. A constructor must always invoke its supper class constructor in its first statement.
A. True
B. False
C.
D.
Answer : B
19. 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
20. The name of the RMI compiler is ___________
A. rmicom
B. rmic
C. jrmi
D. none of the above
Answer : B
21. 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
22. Which of the following represent legal flow control statements?
A. break();
B. continue(inner);
C. return;
D. exit();
Answer : C
23. The length of a string object 's1' can be obtained using the expression s1.length.
A. True
B. False
C.
D.
Answer : B
24. The default case is always required in the switch selection structure.
A. True
B. False
C.
D.
Answer : B
25. Every method of a final in class is implicitly final.
A. True
B. False
C.
D.
Answer : A
26. Declarations can appear anywhere in the body of a Java method.
A. True
B. False
C.
D.
Answer : A
27. Java always provides a default constructor to a class.
A. True
B. False
C.
D.
Answer : B
28. 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
29. In RMI before running the client program we must start RMI Registry.
A. True.
B. False.
C.
D.
Answer : A
30. 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
31. Every call to wait has a corresponding call to notify that will eventually end the wafting.
A. True
B. False
C.
D.
Answer : A
32. Java is fully object oriented programme.
A. true
B. false
C.
D.
Answer : A
33. A final class may not have any abstract method.
A. True
B. False
C.
D.
Answer : A
34. A catch can have comma-separated multiple arguments.
A. True
B. False
C.
D.
Answer : B
35. Which of the following are not keywords?
A. NULL
B. Implements
C. Protected
D. None of the above
Answer : A
36. A static class method can be invoked by simply using the name of the method alone.
A. True
B. False
C.
D.
Answer : B
37. Which of the following methods can be used to change the size of a
size() *
resize()

A. component
B. dimension()
C. setSize()
D. size()
Answer : C
38. The setBackground() method is part of the class
A. Applet
B. Component
C. Container
D. Object
Answer : B
39. class.forName(...) creates an instance of java ODBC driver
A. True
B. False
C.
D.
Answer : A
40. In the code below, what data types the variable x can have?
A. byte b1 = 5;
B. byte b2 = 10;
C. x = b1 * b2;
D. int short
Answer : D
41. 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
42. DriverManager.getConnection("jdbc:odbc:dsn_name") method does not depend on the class.forName(...) method.
A. True.
B. False.
C.
D.
Answer : B
43. Message-Driven beans act as a listener for the Java Message Service API, processing messages synchronously
A. True
B. False
C.
D.
Answer : B
44. Two methods cannot have the same name in Java.
A. True
B. False
C.
D.
Answer : B
45. Which of the following are the wrapper classes?
A. Random
B. Vector
C. Byte
D. all of the above
Answer : C
46. 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
47. 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
48. The break statement is required in the default case of a switch selection structure.
A. True
B. False
C.
D.
Answer : B
49. When we implement an interface method, it should be declared as public.
A. True
B. False
C.
D.
Answer : A
50. 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

Sharing is caring