Download Document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
JAVA LANGUAGE
MULITPLE CHOICE
QUESTION SET-3
1. Which interface provides the
capability to store objects using a
key-value pair?
Java.util.Map
Java.util.Set
Java.util.List
Java.util.Collection
www.prolearninghub.com
2. Which one is not a correct
declaration of a class?
final public class Test
{}
class $Test{}
static class Test {}
public abstract class
_Test {}
www.prolearninghub.com
3. How can we ensure this ?
A method within a class is only
accessible by classes that are defined
within the same package.
Declare the method
with the keyword
public
Declare the method
with keyword protected
Declare the method
with keyword private
Without any
accessibility specifiers.
www.prolearninghub.com
4. ------- method is used to
initialize a class object?
Abstract method
Static method
Constructor
Overloaded method
www.prolearninghub.com
5. What condition should be true
for two overloaded methods?
Same name and same
number of parameter
but different return type.
They have same name.
They have different
name but same number
of argument.
Have same name but
different parameters.
www.prolearninghub.com
6. Which expression doesn’t create
an object of class Student {}?
new Student();
Student s1 = new
Student(), s2 = new
Student();
Student s1;
Student ss = new
StudenStudent s1;t();
www.prolearninghub.com
7. ----- is used to refer a current
class object
Public
This
Static
None of these
www.prolearninghub.com
8. Which of the following is
responsible for garbage collection
Java compiler
Object class
Java virtual machine
System class
www.prolearninghub.com
9. const int x = 10;
Is this statement is correct
declaration of constant in java.
NO
Yes
Can’t say
None
www.prolearninghub.com
10. ----- cannot make final.
Constructor
Destructor
Public class
Private class
www.prolearninghub.com
10.which line produce error.
class Test{
static int x = 100;
// line
int y = 200;
// line 4
public static void main(String []args) {
final int z;
// line 7
z = x + y;
// line 8
System.out.println(z) }}
Line 3
Line 4
Line 7
Line 8
www.prolearninghub.com
12. What is the most restrictive
access modifier that will allow
members of one class to have
access to members of another class
in the same package?
Public
Abstract
Protected
Default access
www.prolearninghub.com
13. Which of the following is/are
correct way of method
declarations?
Protected abstract void
m1();
static final void m1(){};
synchronized public final
void m1() {}
Private native void m1()
www.prolearninghub.com
14. String is a Java-------?
Class
Object
Variable
Character array
www.prolearninghub.com
15. To obtain character at specified
index we use----- method?
char()
Charat()
charat()
charAt()
www.prolearninghub.com
16. isequal() is used to:
equalize two strings
concat two strings
count no of characters
none of above
www.prolearninghub.com
17. String object can create:
(Choose all that apply)
By
by string literal
by final keyword
by new keyword
none of mentioned
www.prolearninghub.com
18. what will be the output for the
following program?
public class StringExample{
public static void main(String args[]){
String s1=“pro";
char ch[]={‘l',‘e',’a',‘r','n',‘i,‘n‘g,‘};
String s2=new String(ch);
System.out.println(s1);
System.out.println(s2); }}
pro, learning
‘l',‘e',’a',‘r','n',‘i,‘n‘g,‘
Learning
None of these
www.prolearninghub.com
19. The method used to return
char value for a particular index
is:
length()
substring()
charAt()
contains()
www.prolearninghub.com
20. The method used to return
string length:
length()
substring()
charAt()
charAt()
www.prolearninghub.com
21. ------ method is used to return
formatted length:
length()
join()
format()
isemptxy()
www.prolearninghub.com
22. object is a object that cannot
be changed when it is created?
Static object
Local object
Immutable object
None of these
www.prolearninghub.com
23. Which of the following is not a
valid way to create String object?
String str2 = new
String(new
char[]{'a','b','c'});
String str = new
String("abc");
String str1 = "abc";
String str3 = 'a'+'b'+'c';
www.prolearninghub.com
24. The memory which store string
object is known as?
Heap
Stack
String constant pool
Method area
www.prolearninghub.com
25.
import myLibrary.*;
public class ShowSomeClass {
// code for the class...}
What is the name of the java file
containing this program?
myLibrary.java
ShowSomeClass.java
ShowSomeClass
ShowSomeClass.class
www.prolearninghub.com
26.
String river = new String(‘ USA ’);
System.out.println (river.length());
What is printed?
2
3
4
5
www.prolearninghub.com
27. If s = “proleaning” what will
be returned by s.length()
function?
9
12
11
0
www.prolearninghub.com
28. What is the difference between
a TextArea and a TextField?
A TextArea can handle
multiple lines of text
TextArea is not a class
A TextArea can be used
for output
TextAreas are used for
displaying graphics
www.prolearninghub.com
29. What keyword is sued to
define a package?
Package
Void package
New package
None of mentioned
www.prolearninghub.com
30. ------ is a multi-way branch
statement?
Switch
Continue
Break
Label
www.prolearninghub.com
31. integer.setDouble
(4.0*5.3+1.5). What data-type
integer has?
Text field
Double field
Int field
double
www.prolearninghub.com
32. What do you mean by a
compound statement?
A collection of one or
more statements
enclosed in braces
A statement involving
if and else
A way of declaring
variables
A way of setting the
value of a variable
www.prolearninghub.com
33. What will be the result of this
code?
String str = "StudyTonight";
str.concat(".com");s
tr = str.toUpperCase();
str.replace("TONIGHT","today");
System.out.println(str)
STUDYTONIGHT
STUDYtoday.com
STUDYTONIGHT.COM
STUDYtoday
www.prolearninghub.com
34.
String str = new String (“hello world”);
How many object this code will
create?
0
2
1
3
www.prolearninghub.com
35. Which method is used to
convert a primitive type into
String?
valueOf ()
toString()
toChar()
None of above
www.prolearninghub.com
36. Trim function is used?
To count spaces
To count spaces
To add spaces
None of the mentioned
www.prolearninghub.com
37. What will be the output for this
code?
String str = "java is a object oriented language";
System.out.println(str.substring(16));
Java is a
Object oriented
Object oriented
language
Language
www.prolearninghub.com
38. What will happen if you try to
compile and run the following
code?
public class MyClass {
public static void main(String arguments[]){ }
public void amethod(String[] arguments)
Error can’t make static
reference to void method.
Error method main not
correct
Error array must include
parameter
A method must be
declared with
String
www.prolearning
hub.com
39. What will be the output for
this code?
String str = “prolearningHub";
StringBuffer sb = new StringBuffer();
for(int i=0; i < str.length(); i++)
sb.append(str.charAt(i));
System.out.println(sb);
It will not print anything
It will print
prolearningHub
It will print
prolearningHub
Error
www.prolearninghub.com
40. What will be the output for
this code?
class Testimmutablestring{
public static void main(String args[]){
String s="Pro";
s.concat(" Learning");
System.out.println(s);
Pro
Learning
Bil clin
Pro Learning
www.prolearninghub.com
41. What will be the output for
this code?
class Testimmutablestring1{
public static void main(String args[]){
String s="Pro";
s=s.concat(" Learning");
System.out.println(s);
Pro
Learning
Pro Learning
None of mentioned
www.prolearninghub.com
42. = = operator is used:
To equalize
To concatenation
To truncate
None of these
www.prolearninghub.com
43. What will be the output for
this program?
class Test{
public static void main(String args[]){
String a="Obama";
String b="Obama";
System.out.println(a.compareTo(b));
System.out.println(a.compareTo(c));
0 1
0 0
1 0
1 1
www.prolearninghub.com
44. What is the base class for all
exception?
java.lang.Exception
java.lang.Throwable
java.lang.DivideByZeroEx
ception
java.lang.ArithmeticExce
ption
www.prolearninghub.com
45. Which type of exception will
be thrown when you run this
code?
int a = 100, b = 0;
int c = a/b;
java.lang.Exception
java.lang.Throwable
java.lang.DivideByZer
oException
java.lang.ArithmeticEx
ception
www.prolearninghub.com
46. What will happen when an
exception occurs inside your
code?
Program will terminate
without showing any
result.
Program will terminate
showing any error
message.
Java will provide a
default exception
handler, which will print
the exception details on
the terminal.
System crashes.
www.prolearninghub.com
47. There are ---- types of
exceptions?
3
4
6
5
www.prolearninghub.com
48. Null pointer exception is ------ exception?
Checked
Unchecked
Error
None of these
www.prolearninghub.com
49. IO exception is -------?
Checked exception
Unchecked exception
Error
None of mentioned
www.prolearninghub.com
50. What should replace XXXX ?
class MyException extends Exception {
public void method() throws XXXX {
throw new MyException();
Error
My exception
Runtime exception
Throws clause isn’t
required
www.prolearninghub.com