Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4K views13 pages

Java MCQ Test Review - 24 Questions

The document describes a Java test containing 24 multiple choice questions. The test covers topics like OOP concepts, variables, operators, inheritance and method overriding. It provides the question, multiple answer options and marks awarded for each question. The output displays the total marks and grade obtained by the candidate.

Uploaded by

subhabirajdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4K views13 pages

Java MCQ Test Review - 24 Questions

The document describes a Java test containing 24 multiple choice questions. The test covers topics like OOP concepts, variables, operators, inheritance and method overriding. It provides the question, multiple answer options and marks awarded for each question. The output displays the total marks and grade obtained by the candidate.

Uploaded by

subhabirajdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

6/30/2021 Java-Test-24mcqs-8qs

Started on Wednesday, 30 June 2021, 6:20 AM


State Finished
Completed on Wednesday, 30 June 2021, 6:53 AM
Time taken 32 mins 59 secs
Marks 28.00/40.00
Grade 70.00 out of a maximum of 100.00

Question 1 A class can have any number of constructors that differ in parameter lists by using _____________.
Complete
Mark 0.00 out of Select one:
1.00 method overriding
Flag question method overloading
constructor overloading
constructor overriding

Question 2 In which portlet do we write the code in the Eclipse IDE?


Complete
Mark 1.00 out of Select one:
1.00 None of these
Flag question Outline
Package Explorer
Editor

Question 3 What will be printed using following code block?


Complete int[] a = {0,1,2,3,4,5,6,7};
Mark 1.00 out of System.out.println(a.length);
1.00

Flag question Select one:


6
7
8

https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 1/13
6/30/2021 Java-Test-24mcqs-8qs

Question 4 What will be the output of the following program?


Complete class variable_scope {
Mark 1.00 out of public static void main(String args[])
1.00 {
Flag question int x;
x = 5;
{
int y = 6;
System.out.print(x + " " + y);
}
System.out.println(x + " " + y);
}
}

Select one:
565
Compilation Error
Runtime Error
5656

Question 5 A subclass will not inherit


Complete
Mark 1.00 out of Select one:
1.00 All of them
Flag question Private members of its parents
Protected members of its parent
Public members of its parent

Question 6 Which of the following loops will execute at least once even when condition controlling the loop is false?
Complete
Mark 1.00 out of Select one:
1.00 do-while

https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 2/13
6/30/2021 Java-Test-24mcqs-8qs

Flag question switch


for
while

Question 7 Which keyword is used to call methods of the parent class?


Complete
Mark 1.00 out of Select one:
1.00 parent
Flag question class
super
this

Question 8 We use ______________ to create an object for the class.


Complete
Mark 1.00 out of Select one:
1.00 dot operator
Flag question
new keyword
this keyword
non-static block

Question 9 What will be the output of the following program?


Complete class string_class {
Mark 1.00 out of public static void main(String args[])
1.00 {
Flag question
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
obj2 = " world";
System.out.println(obj + " " + obj2);
}
}

Select one:

https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 3/13
6/30/2021 Java-Test-24mcqs-8qs

hello hello
world hello
hello world
world world

Question 10 Which of these cannot be used for a variable name in Java?


Complete
Mark 1.00 out of Select one:
1.00 keyword
Flag question identifier
none of the mentioned
both a and b

Question 11 _____________ is returned by greater than (>) and equal to (==) operator.
Complete
Mark 1.00 out of Select one:
1.00 Integers
Flag question Floating - point numbers
None of the mentioned
Boolean

Question 12 What will be the output of the following program?


Complete class operators {
Mark 0.00 out of public static void main(String args[])
1.00 {
Flag question
int var1 = 5;
int var2 = 6;
int var3;
var3 = var2 * var1 / var2 + var2;
System.out.print(var3);
}
}

https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 4/13
6/30/2021 Java-Test-24mcqs-8qs

Select one:
12
11
5
6

Question 13 Which of the following is a method having same name as that of it's class?
Complete
Mark 1.00 out of Select one:
1.00 class
Flag question constructor
delete
finalize

Question 14 What will be the output of the following program?


Complete class Relational_operator {
Mark 1.00 out of public static void main(String args[])
1.00 {
Flag question
int var1 = 5;
int var2 = 6;
System.out.print(var1 > var2);
}
}

Select one:
1
0
false
true

Question 15 What will be the output of the following program?


Complete class Test2{

https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 5/13
6/30/2021 Java-Test-24mcqs-8qs
Mark 0.00 out of public static void main(String arg[])
1.00

Flag question {
String s1="I have learnt ";
String s2="Java";
String s=s1+s2;
System.out.println(s);
}

Select one:
I have learnt Java
Compilation error
I have learntJava
Runtime Error

Question 16 What will be the output of the following


Complete class A {
Mark 1.00 out of public void print() {
1.00 System.out.println(“Class A”);
Flag question
}
}
class B extends A {
public void print() {
System.out.println(“Class B”);
super.print();
}
}

Select one:
Class B
Class A
Class A
Class B
Class B
Class A

https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 6/13
6/30/2021 Java-Test-24mcqs-8qs

Question 17 The following line of code creates an object for the class named Tutorial. What is tut1 here?
Complete Tutorial tut1= new Tutorial();
Mark 1.00 out of
1.00
Select one:
Flag question instance variable
reference variable
object
instance

Question 18 What is System.in in new InputStreamReader(System.in)?


Complete
Mark 1.00 out of Select one:
1.00 An object to standard input stream of type InputStream
Flag question An object to standard input stream of type InputStreamReader
An object to standard input stream of type ByteArrayInputStream
None of these

Question 19 What will be the output of the following program?


Complete class string_demo {
Mark 1.00 out of public static void main(String args[])
1.00 {
Flag question
String obj = "I" + "like" + "Java";
System.out.println(obj);
}
}

Select one:
Java
IlikeJava
I
like

https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 7/13
6/30/2021 Java-Test-24mcqs-8qs

Question 20 Which is a valid declaration of a string?


Complete
Mark 1.00 out of Select one:
1.00 String s4 = (String) '\ufeed';
Flag question String s2 = 'null';
String s3 = (String) 'abc';
String s1 = null;

Question 21 Which of the following is used to avoid naming conflicts?


Complete
Mark 1.00 out of Select one:
1.00 this keyword
Flag question new keyword
non-static block
static block

Question 22 When does method overloading is determined?


Complete
Mark 1.00 out of Select one:
1.00 At compile time
Flag question At run time
At execution time
At coding time

Question 23 Point out the error line in the following program.


Complete 1.class area{
Mark 0.00 out of 2.public static void main(String args[])
1.00 3.{
Flag question 4.int r, pi, a;
5.r = 9;
6.pi = 3.14;
7.a = pi * r * r;

https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 8/13
6/30/2021 Java-Test-24mcqs-8qs

8.System.out.println(a);
9.}
10.}

Select one:
Line number 5
Line number 6
None of these
Line number 7

Question 24 Point out the error in the following program:


Complete 1.class increment {
Mark 0.00 out of 2.public static void main(String args[])
1.00 3.{
Flag question
4.int var1 = 1 + 5;
5.int var2 = var1 / 4;
6.double var3 = 1 + 5;
7.double var4 = var3 / 4;
8.System.out.print(var2 + " " + var4);
9.}
10.}

Select one:
Line number 5
No Error
Line number 6
Line number 7

Question 25 Which of the following declaration(s) is/are correct? Tick all correct answer(s). No partial marks and no negative marks.
Complete
Mark 0.00 out of Select one or more:
2.00 String s="null";
Flag question boolean b=true;
int i=new Integer("56");
byte b1=255;
https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 9/13
6/30/2021 Java-Test-24mcqs-8qs

Question 26 Which of the following operators can operate on a boolean variable? Tick all correct answer(s). No partial marks and no negative
Complete marks.
Mark 2.00 out of
2.00 Select one or more:
Flag question ==
+=
&&
||

Question 27 What does an object of a class consist of?


Complete
Mark 2.00 out of Select one or more:
2.00 behavior
Flag question state
none of these
keywords

Question 28 Select the missing code lines from the dropdown provided.
Complete The java code given below should subtract the smaller number from the greater number.
Mark 2.00 out of But, line numbers 6 and 17 are missing.
2.00

Flag question 1. import java.io.*;


2. class Subtract
3. {
4. public int getDifference(int a, int b)
5. {
6. ---------------Missing code -------------------
7. {
8. return a-b;
9. }
10. else
11. {
12. return b-a;
13. }
https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 10/13
6/30/2021 Java-Test-24mcqs-8qs

14. }
15. public static void main(String a[])
16. {
17. ---------------Missing code -------------------
18. System.out.println(obj.getDifference(4, 7));
19. }
20. }

Line 6 if(a>b)

Line 17 Subtract obj = new Subtract();

Question 29 Select the missing code lines from the dropdown provided.
Complete The java code given below should check whether the number is divisible by 19 or not.
Mark 0.00 out of But, line numbers 6 and 18 are missing.
2.00

Flag question 1. import java.io.*;


2. class Divisible
3. {
4. public String check(int a)
5. {
6. --------------Missing code -------------------
7. {
8. return a+" is divisible by 19" ;
9. }
10. else
11. {
12. return a+" is not divisible by 19" ;
13. }
14. }
15. public static void main(String a[])
16. {
17. Divisible obj = new Divisible();
18. --------------Missing code -------------------
19. }
20. }

Line 6 if(a==0)

Line 18
https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 11/13
6/30/2021 Java-Test-24mcqs-8qs

System.out.println(obj.check(19));

Question 30 Select the missing code lines from the dropdown provided.
Complete The java code given below should check whether an integer is positive, negative or zero.
Mark 1.00 out of But, line numbers 6 and 16 are missing.
2.00

Flag question 1. import java.io.*;


2. class IntegerCheck
3. {
4. public String check(int a)
5. {
6. ---------------Missing code -------------------
7. {
8. return "The number is positive";
9. }
10. else if(a<0)
11. {
12. return "The number is negative";
13. }
14. else
15. {
16. ---------------Missing code -------------------
17. }
18. }
19. public static void main(String a[])
20. {
21. IntegerCheck obj = new IntegerCheck();
22. System.out.println(obj.check(0));
23. }
24. }

Line 6 if(a>0)

Line 16 if(a<0)

Question 31 Find the output of the following code. Type the answer in the correct case.
Complete

https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 12/13
6/30/2021 Java-Test-24mcqs-8qs
Mark 2.00 out of public class Hello {
2.00
public static void main(String[] args)
Flag question {
if(null==null)
System.out.println("Hello");
}
}

Answer: Hello

Question 32 What will be the output of the following program? Type the answer in digits not in alphabets.
Complete
Mark 0.00 out of public class MyNumber {
2.00 public static void main(String[] args)
Flag question {
int number=1;
int number2=12;
while(number<number2)
{
number=number+1;
}
System.out.println(number);
}
}

Answer: 12

https://onlinetest.spoken-tutorial.org/mod/quiz/review.php?attempt=1405653&showall=1 13/13

You might also like