Java/Java Mcq Question Set 3 Sample Test,Sample questions

Question:
 Output : public class Test{ public static void main(String args[]){ int i = 1; do{ i--; }while(i > 2); System.out.println(i); }

1.0

2.1

3.2

4.3

Posted Date:-2021-10-25 05:21:08


Question:
 Output : public class Test{public static void main(String args[]){int i; for(i = 1; i < 6; i++){if(i > 3) continue ; } System.out.println(i); } }

1.5

2.6

3.7

4.8

Posted Date:-2021-10-25 05:21:08


Question:
Choose the correct statement in context of the following program code. public class Test{public static void main(String[] args){double sum = 0; for(double d = 0; d < 10;){d += 0.1; sum += sum + d; }}

1.The program runs in an infinite loop because d<10 would always be true.

2.The program has a compile error because the adjustment is missing in the for loop.

3.The program has a compile error because the control variable in the for loop cannot be of the double type.

4.The program compiles and runs fine.

Posted Date:-2021-10-25 05:21:08


Question:
Given the following piece of code: public class School{ public abstract double numberOfStudent(); } which of the following statements is true?

1.You must add a return statement in method numberOfStudent().

2.The keywords public and abstract cannot be used together.

3.The method numberOfStudent() in class School must have a body.

4.Class School must be defined abstract.

Posted Date:-2021-10-25 05:21:08


Question:
How many Constructor String class have?

1.11

2.12

3.13

4.14

Posted Date:-2021-10-25 05:21:08


Question:
How many objects will be created? String a = new String("Examveda"); String b = new String("Examveda"); String c = "Examveda"; String d = "Examveda";

1.1

2.2

3.3

4.None

Posted Date:-2021-10-25 05:21:08


Question:
How many times will the following code print "Welcome to Gkindiaonline"? int count = 0; do {System.out.println("Welcome to Gkindiaonline"); count++; } while (count < 10);

1.10

2.11

3.12

4.13

Posted Date:-2021-10-25 05:21:08


Question:
In java, ............ can only test for equality, where as .......... can evaluate any type of the Boolean expression.

1.if, switch

2.if, break

3.switch, if

4.continue, if

Posted Date:-2021-10-25 05:21:08


Question:
In which area of memory, the system stores parameters and local variables whenever a method is invoked?

1.Stack

2.Array

3.Heap

4.Storage Area

Posted Date:-2021-10-25 05:21:08


Question:
int ++a = 100 ; System.out.println( ++a ) ; What will be the output of the above fraction of code ?

1.100

2.Displays error as ++a is not enclosed in double quotes in println statement

3.Compiler displays error as ++a is not a valid identifier

4.None of these

Posted Date:-2021-10-25 05:21:08


Question:
int x = 0, y = 0 , z = 0 ; x = (++x + y-- ) * z++; What will be the value of "x" after execution ?

1.0

2.1

3.-1

4.2

Posted Date:-2021-10-25 05:21:08


Question:
Output : class Num { Num(double x ){ System.out.println( x ) ; } } public class Test extends Num {public static void main(String[] args){ Num num = new Num( 2 ) ;} }

1.0

2.1

3.Compile time error

4.None of the above

Posted Date:-2021-10-25 05:21:08


Question:
Output : class Numbers{ public static void main(String args[]){ int a=20, b=10; if((a < b) && (b++ < 25)){ System.out.println("This is any language logic"); } System.out.println(b); } }

1.10

2.11

3.12

4.13

Posted Date:-2021-10-25 05:21:08


Question:
Output : class Test {public static void main(String args[]){int x=7; if(x==2); // Note the semicolon System.out.println("NumberSeven");System.out.println("NotSeven"); } }

1.NotSeven

2.NumberSeven

3.NumberSeven NotSevev

4.None of these

Posted Date:-2021-10-25 05:21:08


Question:
Output : int i = 10; while(i++ <= 10){ i++; } System.out.print(i);

1.11

2.12

3.13

4.14

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test { public static void main(String args[]){ int a = 42; double b = 42.25; System.out.print((a)+" "+(b)); } }

1.2 2.5

2.4.2 4.225

3.2 4.225

4.4.2 4.225

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test {public static void main(String... args) throws Exception{Integer i = 34; int l = 34;if(i.equals(l)){System.out.println("true"); }else{System.out.println("false"); } } }

1.TRUE

2.FALSE

3.Compiler error

4.None of these

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test{ public static void main (String[] args){ String test = "a1b2c3"; String[] tokens = test.split("\d"); for(String s: tokens) system.out.print(s); } }

1.123

2.321

3.abc

4.cba

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test{ public static void main(String args[]){ String str1 = "one";String str2 = "two" ; System.out.println(str1.concat(str2)); } }

1.one

2.two

3.onetwo

4.twoone

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test{ public static void main(String args[]){System.out.println( Math.floor( Math.random( ) ) ) ; } }

1.0

2.0.5

3.1

4.10

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test{ public static void main(String... args){ int a=5 , b=6, c=7; System.out.println("Value is "+ b + c); System.out.println(a + b + c); System.out.println("String " + (b+c)); }

1.Value is 13 18 String

2.Value is 67 18 String 13

3.Value is 13 18 String 13

4.Compilation fails

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test{ public static void main(String... args){int x =5; x *= 3 + 7; System.out.println(x); } }

1.10

2.25

3.35

4.50

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test{ public static void main(String[] args){ int x = 3, y = 4; switch(x + 3){ case 6: y = 0; case 7: y = 1; default: y += 1; } } }

1.0

2.1

3.2

4.3

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test{public static void main(String args[]){ int i, j; for(i=1, j=0;i<10;i++) j += i; System.out.println(i); } }

1.8

2.9

3.10

4.11

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test{public static void main(String args[]){int i = 0, j = 5 ; for( ; (i < 3) && (j++ < 10) ; i++ ){System.out.print(" " + i + " " + j ); }System.out.print(" " + i + " " + j ); }

1.0 6 1 7 2 8 3 8

2.0 6 1 7 2 8 3 9

3.0 6 1 5 2 5 3 5

4.Compilation Error

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test{public static void main(String[] args){String value = "abc"; changeValue(value); System.out.println(value); }public static void changeValue(String a){a = "xyz"; }}

1.xyz

2.abc

3.Compilation fails

4.Compilation clean but no output

Posted Date:-2021-10-25 05:21:08


Question:
Output : public class Test{static public void main(String args[]){ //line 2 int i, j; for(i=0; i<3; i++){for(j=1; j<4; j++){ i%=j; System.out.println(j); } } }

1.Repeatedly print 1 2 3 and cause infinite loop.

2.1 2 3 1

3.1 2 3 2

4.None of these

Posted Date:-2021-10-25 05:21:08


Question:
public class MyClass{ } For the above class(MyClass) what is the correct way of declaring constructor?

1.MyClass(){}

2.public MyClass(){}

3.1 and 3

4.None of these

Posted Date:-2021-10-25 05:21:08


Question:
public class Test { } What is the prototype of the default constructor?

1.public Test( )

2.public Test(void)

3.Test(void)

4.Test( )

Posted Date:-2021-10-25 05:21:08


Question:
Select from among the following character escape code which is not available in Java.

1.a

2.

3.

4.\

Posted Date:-2021-10-25 05:21:08


Question:
The class string belongs to ................. package.

1.java.lang

2.java.awt

3.java.string

4.java.applet

Posted Date:-2021-10-25 05:21:08


Question:
The finalize() method is called just prior to

1.An object, variable or method goes out of scope.

2.An object or variable goes out of scope.

3.A variable goes out of scope.

4.Before garbage collection.

Posted Date:-2021-10-25 05:21:08


Question:
The implicit return type of a constructor is

1.void

2.There is no return type

3.A class object in which it is defined.

4.None of the above

Posted Date:-2021-10-25 05:21:08


Question:
The main method should be static for the reason

1.It can be accessed easily by the class loader.

2.It can be executed without creating any instance of the class.

3.It can be accessed by every method or variable without any hindrance.

4.None of the above

Posted Date:-2021-10-25 05:21:08


Question:
The variables declared in a class for the use of all methods of the class are called

1.instance variables

2.reference variables

3.objects

4.None of these

Posted Date:-2021-10-25 05:21:08


Question:
What is Math.floor(3.6)?

1.3

2.4

3.3

4.4

Posted Date:-2021-10-25 05:21:08


Question:
What is the value of a[1] after the following code is executed? int[] a = {0, 2, 4, 1, 3}; for(int i = 0; i < a.length; i++) a[i] = a[(a[i] + 3) % a.length];

1.0

2.1

3.2

4.3

Posted Date:-2021-10-25 05:21:08


Question:
What will be output? String S1 = "S1 ="+ "123"+"456"; String S2 = "S2 ="+(123+456);

1.S1=579,S2=579

2.S1=123456,S2=123456

3.S1=12345, S2=57

4.S1=123456, S2=579

Posted Date:-2021-10-25 05:21:08


Question:
What will be the output? if(1 + 1 + 1 + 1 + 1 == 5){ System.out.print("TRUE"); } else{ System.out.print("FLASE"); }

1.TRUE

2.FALSE

3.Compiler Error

4.None of these

Posted Date:-2021-10-25 05:21:08


Question:
What will be the return type of a method that not returns any value?

1.void

2.int

3.double

4.None of the above

Posted Date:-2021-10-25 05:21:08


Question:
Which of the following class definitions defines a legal abstract class?

1.abstract class A { abstract void unfinished(); }

2.abstract class A { abstract void unfinished(); }

3.class A { abstract void unfinished(); }

4.class A { abstract void unfinished() { } }

Posted Date:-2021-10-25 05:21:08


Question:
Which of the following for loops will be an infinite loop?

1.for(i=0 ; i<1; i--)

2.for(i=0; ; i++)

3.for(; ;)

4.All of the above

Posted Date:-2021-10-25 05:21:08


Question:
Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?

1.(1 > x > 100) || (x < 0)

2.1 < x < 100 || x < 0

3.((x < 100) && (x > 1)) || (x < 0)

4.((x < 100) && (x > 1)) && (x < 0)

Posted Date:-2021-10-25 05:21:08


Question:
Which of the following options is the best for generating random integer 0 or 1?

1.(int)Math.random()

2.(int)Math.random() + 1

3.(int)(Math.random() + 0.2)

4.(int)(Math.random() + 0.5)

Posted Date:-2021-10-25 05:21:08


Question:
Which of these is a legal definition of a method named gkindiaonline assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct

1.gkindiaonline() throw IOException{}

2.void gkindiaonline() throw IOException{}

3.void gkindiaonline() throws IOException{}

4.void gkindiaonline(void) throws IOException{}

Posted Date:-2021-10-25 05:21:08


Question:
___________ method cannot be overridden.

1.static

2.final

3.super

4.private

Posted Date:-2021-10-25 05:21:08


More MCQS

  1. Java Mcq Question Set 1
  2. Java Mcq Question Set 2
  3. Java Mcq Question Set 3
  4. Java Mcq Question Set 4
  5. Java Mcq Question Set 5
  6. Java Mcq Question Set 6
  7. Java Mcq Question Set 7
  8. Java Mcq Question Set 8
  9. Java Mcq Question Set 9
  10. Java Multiple Choice Questions
  11. DATA TYPES IN JAVA
  12. Classes ,Constructor ,Methods,Inheritance
  13. Java Multiple Choice Questions.
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!