Home

Java Programming 1000+ MCQ with answer for SSC Stenographer

Thursday 9th of March 2023

Sharing is caring

1. When we invoke repaint () for a Component, the AWT invokes the method:
A. draw()
B. update()
C. show()
D. paint()
Answer : B
2. Which of the following classes are available in the java.lang package?
A. Random
B. Stack
C. String Buffer
D. Vector
Answer : A
3. Frames and applets cannot be used together in the same program.
A. True
B. False
C.
D.
Answer : B
4. forName() is a static factory method
A. True
B. False
C.
D.
Answer : A
5. 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
6. Consider the following code snippet:
try 
{
int x=0; int y=50/x;
System.out.println("Division by zero");
}
catch(ArithmeticException e)
{
System.out.println("catch block");
}

What will be the output?

A. Error. Won't compile
B. Division by zero
C. Catch block
D. Division by zero catch block
Answer : C
7. 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
8. A method declared as static can not access non-static class members.
A. True
B. False
C.
D.
Answer : A
9. A string object can not be modified after it is created.
A. True
B. False
C.
D.
Answer : A
10. Which of the following represent legal flow control statements?
A. break();
B. continue(inner);
C. return;
D. exit();
Answer : C
11. A class may be both abstract and final.
A. True
B. False
C.
D.
Answer : B
12. 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
13. The setBackground() method is part of the class
A. Applet
B. Component
C. Container
D. Object
Answer : B
14. 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
15. Two methods cannot have the same name in Java.
A. True
B. False
C.
D.
Answer : B
16. Which javadoc tag is used to denote a comment for methods parameters?
A. @method
B. @parameter
C. @argument
D. @param
Answer : D
17. 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
18. All methods in an abstract class must be declared abstract.
A. True
B. False
C.
D.
Answer : B
19. 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
20. A panel can not be added to another panel.
A. True
B. False
C.
D.
Answer : B
21. 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
22. Any method in a supper class can be over ridden in its subclass.
A. True
B. False
C.
D.
Answer : B
23. With javadoc, which of the following denotes a javadoc comment?
A. //#
B. /*
C. /**
D. //**
Answer : C
24. Servlet has ___________
A. init method
B. doGet(------) method
C. All of the above methods.
D.
Answer : C
25. A Java monitor must either extend thread class or implement Runnable interface.
A. True
B. False
C.
D.
Answer : B
26. 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
27. Which of the following are the wrapper classes?
A. Random
B. Vector
C. Byte
D. all of the above
Answer : C
28. 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
29. 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
30. When we implement an interface method, it should be declared as public.
A. True
B. False
C.
D.
Answer : A
31. 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
32. 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
33. Every method of a final in class is implicitly final.
A. True
B. False
C.
D.
Answer : A
34. 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
35. 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
36. A variable declared inside the for loop control can not be referenced out side the loop.
A. True
B. False
C.
D.
Answer : A
37. Which of the following are not keywords?
A. NULL
B. Implements
C. Protected
D. None of the above
Answer : A
38. 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
39. Java always provides a default constructor to a class.
A. True
B. False
C.
D.
Answer : B
40. 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
41. The name of the RMI compiler is ___________
A. rmicom
B. rmic
C. jrmi
D. none of the above
Answer : B
42. When we implement the Runnable interface, we must define the method
A. start()
B. init()
C. runnable()
D. run()
Answer : D
43. The methods wait() and noify() are defined in
A. java.lang.Thread
B. java.lang.Runnable
C. java.lang.Object
D. java.lang.ThreadGroup
Answer : C
44. Declaring a method synchronized guarantees that the deadlock cannot occur.
A. True
B. False
C.
D.
Answer : A
45. 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
46. Declarations can appear anywhere in the body of a Java method.
A. True
B. False
C.
D.
Answer : A
47. A static class method can be invoked by simply using the name of the method alone.
A. True
B. False
C.
D.
Answer : B
48. Servlet can have ___________
A. get method and post method
B. get method or post method
C. Either of the above
D.
Answer : C
49. Java is fully object oriented programme.
A. true
B. false
C.
D.
Answer : A
50. 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

Sharing is caring