MCQ
1. A package is container of
_____
|
||||||
A. Methods
|
B. Objects
|
C. Classes
|
D. Variables
|
|||
2. If a variable is declared as
private , then it can be used in _______
|
||||||
A. Any class of any package
|
B. Any class of same package
|
C. Only in the same class
|
D. Only subclass in that package
|
|||
3. which package is imported
implicitly?
|
||||||
A. java.applet
|
B. java.util
|
C. java.lang
|
D. java.io
|
|||
4. Math class is in ………package.
|
||||||
A. java.io
|
B. java.lang
|
C. java.util
|
D.java.applet
|
|||
5. syntax of pow()method
is…….
|
||||||
A. double pow(double a, double b)
|
||||||
B. double pow(int a, int b)
|
||||||
C. int pow(int a, int b)
|
||||||
D. double pow(int a)
|
||||||
6 . write a output of following
class MathEx
{
public static void
main(String args[])
{
double
a=123.34;
double b=234.56;
System.out.println(“a=”+Math.ceil(a));
System.out.println(“b=”+Math.floor(b));
}
}
|
||||||
A.a=123 b=234
|
||||||
B.a=124 b=235
|
||||||
C.a=124 b=234
|
||||||
D.a=123 b=235
|
||||||
7. write a output of following
|
||||||
Class MathTest
{
public static void
main(string arg[]
{
double a=123.456;
System.out.println(Math.rint(a));
}
}
|
||||||
A. 123.46
|
B. 123
|
C.124
|
D.123.0
|
|||
8. The data type wrapper classes
are in……….package
|
||||||
A.java.lang
|
B.java.io
|
C.java.util
|
D.java.applet
|
|||
9. syntax of getTime() method is
…………..
|
||||||
a. date getTime()
|
b. void getTime(date d)
|
|||||
c. long getTime()
|
d. long getTime(date d)
|
|||||
10. find errors if any otherwise write output:
class Ex
{
Public static void
main(String args[])
{
Date d=new date();
System.out.println(“date is:”+d);
}
}
|
||||||
A. it will print the whole current date and time
|
||||||
B.it will print the current date
|
||||||
C. error:date class and constructor not found
|
||||||
D.error:can not print object d
|
||||||
11. The random class is in
……..package
|
||||||
A.java.io
|
B.java.util
|
C.java.lang
|
D.java.applet
|
|||
12. The…….class creates a
dynamic array
|
||||||
A.vector
|
B.calendar
|
C.random
|
D.object
|
|||
13. To add element in vector
,…….method is used
|
||||||
A.add item()
|
B.insertitem()
|
C.addelement()
|
D.insertelement
|
|||
14. To know the size of a vector
……..method is used
|
||||||
A.length()
|
B.size()
|
C.capacity()
|
D.getsize()
|
|||
15. which method is used to
insert an element into a stack object?
|
||||||
A.insert()
|
B.push()
|
C.pop()
|
D.add()
|
|||
16. which method is used to know
the element add the top of the stack?
|
||||||
A.pop()
|
B.top()
|
C.peek()
|
D.search()
|
|||
17. To delete the top element of
the stack …….method is used?
|
||||||
A.delete()
|
B.pop()
|
C.remove()
|
D.peep()
|
|||
18. To insert a key-value pair
in a hashtable ………method is used?
|
||||||
A.insert()
|
B.put()
|
C.add()
|
D.push()
|
|||
19. To find the value of an
element by it’s key…….method is used?
|
||||||
A.get()
|
B.getvalue()
|
C.pop()
|
D.value()
|
|||
20. In java string is ______
|
||||||
A.
Array of characters
|
B. An
object of String class
|
C. a
single character
|
D. Both
A and B
|
|||
21. Which method is used to find
the position of a particular substring
from a string?
|
||||||
A.
substring()
|
B.
getChars()
|
C.
charAt()
|
D.
indexOf()
|
|||
22. The syntax of charAt()
method is _____
|
||||||
A. int
charAt(int no)
|
B. int
charAt(char ch)
|
|||||
C. char
charAt(int no)
|
D. char
charAt(char no)
|
|||||
23. Which of the following
is a string comparision method ?
|
||||||
A.
startsWith()
|
B.endsWith()
|
|||||
C.
substring()
|
D.
reqionMatches()
|
|||||
24. The ___ class creates a
fixed length string.
|
||||||
A.
String
|
B.
StringBuffer
|
|||||
C.
Character
|
D. All
of above
|
|||||
25. Which method is used to
specify the minimum capacity of the StingBuffer object?
|
||||||
A.
capcity()
|
B.
setCapacity()
|
|||||
C.
ensurureCapacity()
|
D.
setLength()
|
|||||
26. The syntax of delete()
method is ____
|
||||||
A.
StringBuffer delete(char ch)
|
||||||
B.
StringBuffer delete(char ch,int startIndex)
|
||||||
C.
StringBuffer delete(int startIndex,int endIndex)
|
||||||
D.
StringBuffer delete(char ch1,char ch2)
|
||||||
27. Which method is used to
convert a string in uppercase?
|
||||||
A.
uppercase()
|
B.
toUpperCase()
|
|||||
C.
changeCase()
|
D.
capitalize()
|
|||||
28. Write output of following
class
str
{
public static void main(String args[])
{
StringBuffer s=new
StringBuffer(“ABCDE”);
s.setChatAt(3,’X’);
System.out.println(s);
}
}
|
||||||
A.
ABCXDE
|
B.
ABCXE
|
C.
ABXDE
|
D.
ABXCDE
|
|||
29. syntax of replace() of
string class is ____________
|
||||||
A. String replace(char ch1, char ch2)
|
||||||
B. void replace(char ch1, char ch2)
|
||||||
C. String replace(char ch1, int i)
|
||||||
D. void replace(char ch1, int i)
|
||||||
30.Wrapper classes are found in
_____ package
|
||||||
A.
java.lang
|
B.
java.util
|
C.
java.io
|
D.
java.net
|
|||
Answers :
1
|
- C
|
2
|
- C
|
3
|
- C
|
4
|
- B
|
5
|
- A
|
6
|
- C
|
7
|
- D
|
8
|
- A
|
9
|
- C
|
10
|
- C
|
11
|
- B
|
12
|
- A
|
13
|
- C
|
14
|
- B
|
15
|
- B
|
16
|
- C
|
17
|
- B
|
18
|
- B
|
19
|
- A
|
20
|
- B
|
21
|
- D
|
22
|
- C
|
23
|
- C
|
24
|
- A
|
25
|
- C
|
26
|
- C
|
27
|
- B
|
28
|
- B
|
29
|
- A
|
30
|
- A
|
Posted By : Ruchita Pandya