JAVA-Test
1. Multiple inheritance in Java is possible by
Select one:
a) Extending multiple classes
b) Implementing multiple interfaces
c) Both a and b
d) None of them
2. Which of these conditional statements tests only for equality?
Select one:
a) none
b) while
c) if
d) switch
3. Which is a valid declaration of a string?
Select one:
a) String s3 = (String) 'abc';
b) String s2 = 'null';
c) String s1 = null;
d) String s4 = (String) '\ufeed';
4. Which of the following is the correct syntax for creating an object for a
class in Java?
Select one:
a) ClassName obj= ClassName();
b) ClassName obj=new ClassName();
c) ClassName new obj=ClassName();
d) ClassName obj=new();
5. What is the output of relational operators?
Select one:
a) Integer
b) Double
c) Boolean
d) Charac
6. How can we define more than one method in a class differentiated by
method signature?
Select one:
a) Method overriding
b) None of the mentioned
c) Method doubling
d) Method overloading
7. Consider the following code block
int[] a = {5,6,7,8,9};
int[] b = a;
b[2] = 10;
What will be the value of a[2]?
Select one:
a) 8
b) 7
c) 6
d) 10
8. We use ______________ to create an object for the class.
Select one:
a) dot operator
b) new keyword
c) non-static block
d) this keyword
9. Which of the following operators has least precedence in Java?
Select one:
a) less than or equal to
b) greater than or equal to
c) bracket
d) equal to
10. Which of the following statements is correct?
Select one:
a) true is any non zero value and false is 0.
b) true and false are numeric values 0 and 1.
c) true and false are numeric values 1 and 0.
d) true and false are non numeric values.
11. A subclass will not inherit
Select one:
a) All of them
b) Private members of its parents
c) Protected members of its parent
d) Public members of its parent
12. In method overloading, two methods with same name cannot have
Select one:
a) Same return type with same number of parameters
b) Same return type, and same number, type and order of parameters
c) Same number of parameters
d) Same return type
13. What will be the output of the following
class A {
public void print() {
System.out.println(“Class A”);
}
}
class B extends A {
public void print() {
System.out.println(“Class B”);
super.print();
}
}
Select one:
o Class B
o Class A
14. final keyword can not be used in conjunction with ______________.
Select one:
a) Static or non-static variables
b) Class
c) Interface
d) Method
15. Which of the following is not a return type?
Select one:
a) public
b) boolean
c) void
d) int
16. Which of the following is not a feature of java?
Select one:
a) High Performance
b) Multi-threaded
c) Object-Oriented
d) Platform Dependant
17. Which of the following helps in creating dynamic web pages?
Select one:
a) None of them
b) JSP or Java Server Pages
c) J2EE or Java Enterprise Edition
d) Java Applets
18. Which of the following converts the String s="Spoken Tutorial" into upper
case?
Select one:
a) s=s.UpperCase();
b) s=s.toUpper();
c) s=s.Upper();
d) s=s.toUpperCase();
19. Which method can be defined only once in a program?
Select one:
a) private method
b) static method
c) main method
d) finalize method
20. What will be the output of the following program?
class increment {
public static void main(String args[])
{
double var1 = 1 + 5;
double var2 = var1 / 4;
int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4);
}
}
Select one:
a) 01
b) 1.5 1.0
c) 1.5 1
d) 1 1
21. What is the meaning of return datatype void?
Select one:
a) None of these
b) void returns no datatype
c) An empty memory space is returned so that developers can utilize it
d) void is not supported in Java
22. The finally block is executed after
Select one:
a) Successful completion of try block
b) None of them
c) When an exception is thrown
d) Always irrespective of whether an exception was thrown in try block
23. Point out the error in the following lines of code.
1.class abc {
2.public static void main(String args[])
3.{
4.double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
5.float result;
6.result = 0;
7.for (int i = 0; i < 6; ++i)
8.result = result + num[i];
9.System.out.print(result/6);
10.}
11.}
Select one:
a) Line number 4
b) None of these
c) Line number 6
d) Line number 8
24. Point out the error in the following code.
1.class box {
2.int width;
3.int height;
4.int length;
5.int volume;
6.void volume(int height, int length, int width) {
7.volume = width*height*length;
8. }
9. }
10.class Parameterized_method{
11.public static void main(String args[])
12. {
13. box obj = new box();
14. obj.height = 1;
15. obj.length = 5;
16. obj.width = 5;
17. obj.volume(3,2,1);
18. System.out.println(volume);
19. }
}
Select one:
a) Line number 18
b) Line number 7
c) Line number 6
d) None of these
25. Which of the following statement(s) is/are correct? Tick all correct
answer(s). No partial marks and no negative marks.
Select one or more:
a) The default constructor has the same access as its class.
b) The default constructor invokes the no-arg constructor of the superclass.
c) The default constructor initialises method variables.
d) The compiler creates a default constructor only when there are no other
constructors for the class.
26. Which of the following may be part of a class definition? Tick all correct
answer(s). No partial marks and no negative marks.
Select one or more:
a) none of these
b) instance methods
c) constructors
d) instance variables
27. What is the operand of arithmetic operators?
Select one or more:
a) Boolean
b) Characters
c) Numeric
d) None of these
28. Select the missing code lines from the dropdown provided.
The java code given below should find whether the number is odd or even.
But, line numbers 4 and 17 are missing.
import java.io.*;
class EvenOdd
{
---------------Missing code -------------------
{
if(num%2==0)
{
return "Number is even";
}
else
{
return "Number is odd";
}
}
public static void main(String a[])
{
---------------Missing code -------------------
System.out.println(obj.check(36));
}
}
o Line 4 Answer 1
o Line 17 Answer 2
29. Select the missing code lines from the dropdown provided.
The java code given below should check whether an integer is positive, negative
or zero.
But, line numbers 6 and 16 are missing.
import java.io.*;
class IntegerCheck
{
public String check(int a)
{
---------------Missing code -------------------
{
return "The number is positive";
}
else if(a<0)
{
return "The number is negative";
}
else
{
---------------Missing code -------------------
}
}
public static void main(String a[])
{
IntegerCheck obj = new IntegerCheck();
System.out.println(obj.check(0));
}
}
o Line 6 Answer 1
o Line 16 Answer 2
30. Select the missing code lines from the dropdown provided.
The java code given below should find the sum of the digits of a number.
But, line numbers 10 and 12 are missing.
import java.io.*;
class DigitSum
{
public int sum(int num)
{
int total=0;
while(num>0)
{
total= total + num%10;
---------------Missing code -------------------
}
---------------Missing code -------------------
}
public static void main(String a[])
{
DigitSum obj = new DigitSum();
System.out.println(obj.sum(1023));
}
}
o Line 10 Answer 1
o Line 12 Answer 2
31. will be the output of the following program? Type the answer in the correct
case.
class Test2
{
public static void main(String arg[])
{
String s1 = “Java”;
String s2 = “Program”;
String s= s1+s2;
System.out.println(s);
}
}
Answer:
32. What will be the output of the following code? Type the answer in the
correct case.
public class Tutorial {
String tutName;
int tutNo;
public static void main(String[] args) {
Tutorial tut= new Tutorial();
tut.tutName="Java";
System.out.print(tut.tutName);
}
}
Answer:
33. Multiple inheritance in Java is possible by
Select one:
a) Extending multiple classes
b) Implementing multiple interfaces
c) Both a and b
d) None of them
34. Which of these conditional statements tests only for equality?
Select one:
a) none
b) while
c) if
d) switch
35. Which is a valid declaration of a string?
Select one:
a) String s3 = (String) 'abc';
b) String s2 = 'null';
c) String s1 = null;
d) String s4 = (String) '\ufeed';
36. Which of the following is the correct syntax for creating an object for a
class in Java?
Select one:
a) Class Name obj= Class Name();
b) Class Name obj=new Class Name();
c) Class Name new obj=Class Name();
d) Class Name obj=new();
37. What is the output of relational operators?
Select one:
a) Integer
b) Double
c) Boolean
d) Characters
38. How can we define more than one method in a class differentiated by
method signature?
Select one:
a) Method overriding
b) None of the mentioned
c) Method doubling
d) Method overloading
39. We use ______________ to create an object for the class.
Select one:
a) dot operator
b) new keyword
c) non-static block
d) this keyword
40. Which of the following operators has least precedence in Java?
Select one:
a) less than or equal to
b) greater than or equal to
c) bracket
d) equal to
41. Which of the following statements is correct?
Select one:
a) true is any non zero value and false is 0.
b) true and false are numeric values 0 and 1.
c) true and false are numeric values 1 and 0.
d) true and false are non numeric values.
42. A subclass will not inherit
Select one:
a) All of them
b) Private members of its parents
c) Protected members of its parent
d) Public members of its parent
43. In method overloading, two methods with same name cannot have
Select one:
a) Same return type with same number of parameters
b) Same return type, and same number, type and order of parameters
c) Same number of parameters
d) Same return type
44. final keyword can not be used in conjunction with ______________.
Select one:
a) Static or non-static variables
b) Class
c) Interface
d) Method
45. Which of the following is not a return type?
Select one:
a) public
b) boolean
c) void
d) int
46. Which of the following is not a feature of java?
Select one:
a) High Performance
b) Multi-threaded
c) Object-Oriented
d) Platform Dependant
47. Which of the following helps in creating dynamic web pages?
Select one:
a) None of them
b) JSP or Java Server Pages
c) J2EE or Java Enterprise Edition
d) Java Applets
48. Which of the following converts the String s="Spoken Tutorial" into upper
case?
Select one:
a) s=s.UpperCase();
b) s=s.toUpper();
c) s=s.Upper();
d) s=s.toUpperCase();
49. Which method can be defined only once in a program?
Select one:
a) private method
b) static method
c) main method
d) finalize method
50. What will be the output of the following program?
class increment {
public static void main(String args[])
{
double var1 = 1 + 5;
double var2 = var1 / 4;
int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4);
}
}
Select one:
a) 01
b) 1.5 1.0
c) 1.5 1
d) 1 1
51. What is the meaning of return datatype void?
Select one:
a) None of these
b) void returns no datatype
c) An empty memory space is returned so that developers can utilize it
d) void is not supported in Java
52. The finally block is executed after
Select one:
a) Successful completion of try block
b) None of them
c) When an exception is thrown
d) Always irrespective of whether an exception was thrown in try block
53. Point out the error in the following lines of code.
1.class abc {
2.public static void main(String args[])
3.{
4.double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
5.float result;
6.result = 0;
7.for (int i = 0; i < 6; ++i)
8.result = result + num[i];
9.System.out.print(result/6);
10.}
11.}
Select one:
a) Line number 4
b) None of these
c) Line number 6
d) Line number 8
54. Point out the error in the following code.
1.class box {
2.int width;
3.int height;
4.int length;
5.int volume;
6.void volume(int height, int length, int width) {
7.volume = width*height*length;
8. }
9. }
10.class Parameterized_method{
11.public static void main(String args[])
12. {
13. box obj = new box();
14. obj.height = 1;
15. obj.length = 5;
16. obj.width = 5;
17. obj.volume(3,2,1);
18. System.out.println(volume);
19. }
}
Select one:
a) Line number 18
b) Line number 7
c) Line number 6
d) None of these