Home

Java Programming 1000+ MCQ with answer for UPSC CDS

Thursday 9th of March 2023

Sharing is caring

1. It is perfectly legal to refer to any instance variable inside of a static method.
A. True
B. False
C.
D.
Answer : B
2. 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
3. Which of the following statements are true?
A. An abstract class may not have any final methods?
B. A final class may not have any abstracts methods.
C. Transient variables must be static.
D. all of the above
Answer : B
4. 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
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. Servlet has ___________
A. init method
B. doGet(------) method
C. All of the above methods.
D.
Answer : C
7. 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
8. JSP files creates ________________
A. html files
B. html files and java files
C. java files and class files
D. None of the above.
Answer : C
9. An EJB is a server-side component that encapsulates the business logic of an application
A. True
B. False
C.
D.
Answer : A
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. Which of the following are keywords?
A. integer
B. default
C. Boolean
D. Object
Answer : B
12. class.forName(...) creates an instance of java ODBC driver
A. True
B. False
C.
D.
Answer : A
13. Which of the following statements are valid array declarations?
A. int number();
B. float average[];
C. double[] marks;
D. counter int[];
Answer : B
14. All the bitwise operators have the same level of precedence in Java.
A. True
B. False
C.
D.
Answer : A
15. A panel can not be added to another panel.
A. True
B. False
C.
D.
Answer : B
16. 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
17. Which of the following represent legal flow control statements?
A. break();
B. continue(inner);
C. return;
D. exit();
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 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. Declaring a method synchronized guarantees that the deadlock cannot occur.
A. True
B. False
C.
D.
Answer : A
21. Two methods cannot have the same name in Java.
A. True
B. False
C.
D.
Answer : B
22. 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
23. Members of a class specified as private are accessible only to the methods of the class.
A. True
B. False
C.
D.
Answer : A
24. 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
25. Every call to wait has a corresponding call to notify that will eventually end the wafting.
A. True
B. False
C.
D.
Answer : A
26. When present, package must be the first no comment statement in the file.
A. True
B. False
C.
D.
Answer : A
27. The programmer must explicitly create the system .in and system .out objects.
A. True
B. False
C.
D.
Answer : B
28. If a=10 and b= 15, then the statement x =(a>b)?a:b; assigns the value 15 to x.
A. True
B. False
C.
D.
Answer : A
29. Every method of a final in class is implicitly final.
A. True
B. False
C.
D.
Answer : A
30. With javadoc, which of the following denotes a javadoc comment?
A. //#
B. /*
C. /**
D. //**
Answer : C
31. All methods in an abstract class must be declared abstract.
A. True
B. False
C.
D.
Answer : B
32. In RMI we invoke client method from remote server
A. True
B. False
C.
D.
Answer : B
33. 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
34. The use of protected keyword to a member in a class will restrict its visibility as follows:
A. Visibility only in the class and its subclasses in the same package.
B. Visibility only inside the same package.
C. Visibility in all classes in the same package and subclasses in other packages.
D. Visibility only in the class where it is declared.
Answer : C
35. It is perfectly legal to assign a subclass object to a supper class reference.
A. True
B. False
C.
D.
Answer : A
36. The keywords reserved but not used in the initial version of Java re:
A. Synchronized
B. Boolean
C. union
D. goto
Answer : D
37. 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
38. A final class may not have any abstract method.
A. True
B. False
C.
D.
Answer : A
39. Objects are passed to a method by use of call-by-reference.
A. True
B. False
C.
D.
Answer : A
40. When we implement an interface method, it should be declared as public.
A. True
B. False
C.
D.
Answer : A
41. 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
42. We can over load methods with differences only in their return type.
A. True
B. False
C.
D.
Answer : B
43. Which of the following are the wrapper classes?
A. Random
B. Vector
C. Byte
D. all of the above
Answer : C
44. The setBackground() method is part of the class
A. Applet
B. Component
C. Container
D. Object
Answer : B
45. 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
46. The check box group class is a subclass of the component class.
A. True
B. False
C.
D.
Answer : B
47. Declarations can appear anywhere in the body of a Java method.
A. True
B. False
C.
D.
Answer : A
48. 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
49. The length of a string object 's1' can be obtained using the expression s1.length.
A. True
B. False
C.
D.
Answer : B
50. For all insert, update, delete, query operations on a database, ResultSet object creation is mandatory.
A. True.
B. False.
C.
D.
Answer : B

Sharing is caring