Java
Java
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();
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
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
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();
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
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:
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();
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
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
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();