MCQ
Set- 1
Total MCQ – 25
1. What will be the output?
package
Java91.blogspot.in;
public class
TestJava91 {
public static void
main(String[] args) {
int arr[] =
new int[2];
for (int i =
0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
a) 0 0 0
b) ArrayIndexoutOfBoundsException
c) NullPointerException
d) null null null
a) 0 0 0
b) ArrayIndexoutOfBoundsException
c) NullPointerException
d) null null null
2. Which of the following are valid array declarations?
a) int arr[] = new int[];
b) float arr[10] = new fl
c) double []arr = new double[10];
d) None Of the Above.
3. What will be the output?
package Java91.blogspot.in;
public class
TestJava91 {
public void
method() {
System.out.println("Called");
}
public static void
main(String[] args) {
method();
}
}
a) "Called"
b) Compiler
c) Runtime
d) Nothing
a) "Called"
b) Compiler
c) Runtime
d) Nothing
4. What will be the output?
package Java91.blogspot.in;
public class
TestJava91 {
public static void
method() {
System.out.println("Called");
}
public static void
main(String[] args) {
TestJava91 t4 = null;
t4.method();
}
}
a) "Called"
b) Compiler
c) Runtime Exception
d) Nothing is printed in screen
a) "Called"
b) Compiler
c) Runtime Exception
d) Nothing is printed in screen
5. What will be the output?
package Java91.blogspot.in;
public class
TestJava91 {
public void TestJava91()
{
System.out.println("Constructor1
");
}
public
TestJava91() {
System.out.println("Constructor2");
}
public static void
main(String[] args) {
TestJava91 testJava91 = new
TestJava91();
}
}
a) "Constructor1"
b) "Constructor2"
c) "Constructor1""Constructor2"
d) Compiler Errror
6. What will be the output?
package Java91.blogspot.in;
public class
TestJava91 {
public
TestJava91() {
this(4);
}
public
TestJava91(byte var) {
System.out.println(var);
}
public static void
main(String[] args) {
TestJava91 testJava91 = new
TestJava91();
}
}
a) 4
b) 4 4
c) Compiler Error
d) Compiles and Runs without error
7. What will be the output?
package Java91.blogspot.in;
a) 4
b) 4 4
c) Compiler Error
d) Compiles and Runs without error
7. What will be the output?
package Java91.blogspot.in;
public class
TestJava91 {
public
TestJava91(){}
public
TestJava91(TestJava91 ref){
this (ref,"Hai");
}
public
TestJava91(TestJava91 ref,String str){
ref.TestJava91(str);
System.out.println("Hi");
}
public void TestJava91(String str) {
System.out.println(str);
}
public static void
main(String[] args) {
TestJava91 test = new
TestJava91();
TestJava91 test1 = new
TestJava91(test);
}
}
a) HI
b) hai
c) Hai Hi
d) Hi Hai
a) HI
b) hai
c) Hai Hi
d) Hi Hai
8. Which of the following are valid Constructors?
a) public Test8(){}
b) private void Test8(){}
c) protected Test8(int k){}
d) Test8(){}
9. Which of the following are valid method declarations?
a) abstract method(){}
b) abstrct void method(){}
c) final void method(){}
d) int method(){}
10. Which of the following are valid top-level class declarations?
a) class Test10
b) public class Test10
c) final class Test10
d) abstract final class Test10
11. Transient keywaord can be used with?
a) method
b) variable
c) class
d) constructor
12. which of the following are valid combinations for class declaration?
a) abstract final class Test12{}
b) abstract static class Test12{}
c) final static class Test12{}
d) public final strictfp class Test12{}
13. which of the following are valid constructor signatures?
a) public void className()
b) public void className()
c) private className()
d) static className()
14. Which of the following modifiers can be used with top class declaration?
a) static
b) privatr
c) public
d) final
e) abstract
15. Which of the following are valid array declarations?
a) int arr[] = new int[];
b) int arr[][] = new int [10][10];
c) float arr[][] = new float[][10];
d) float arr[] = new float[10];
16. What will be the output of the following program?
package Java91.blogspot.in;
public class
TestJava91 {
static {
System.out.println("Static");
}
{
System.out.println("Instance");
}
public void TestJava91()
{
System.out.println("Constructor");
}
public static void
main(String[] args) {
TestJava91 t = null;
}
}
a)
Instance Static
b) Static Instance
c) Static
d) Static Instance Constructor
b) Static Instance
c) Static
d) Static Instance Constructor
17. What will be the output of the following program?
package Java91.blogspot.in;
class Sup
{
public
Sup(String str) {
System.out.println("Super
class");
}
}
public class
TestJava91 extends Sup {
public TestJava91()
{
System.out.println("Sub
class");
}
public static void
main(String[] args) {
TestJava91 testJava91 = new
TestJava91();
}
}
a) Super class,SubClass
b) Super class
c) Sub class
d) Compiler Error
a) Super class,SubClass
b) Super class
c) Sub class
d) Compiler Error
18. What will be the output of the following program?
package Java91.blogspot.in;
public class
TestJava91 {
public static void
main(String[] args) {
System.out.println("Main
Method1");
}
public static void
main(String args) {
System.out.println("Main
Method2");
}
}
a) Main Method1
b) Main Method1 Main Method2
c) Main Method2
d) Runtime Exception
19. What will be the output of the following program?
package Java91.blogspot.in;
public class
TestJava91 {
public static void
main(String args) {
System.out.println("Sample
Program");
}
}
a) Sample Program
b) Compiler Error
c) Runtime Exception
d) None
20. What will be the output of the following program?
class Sup1 {
public
Sup1() {
System.out.println("Hai");
}
private Sup1(String
str) {
System.out.println(str);
}
}
public class Test5
extends Sup1 {
private
Test5(String str) {
System.out.println(str);
super();
}
public static void
main(String[] args) {
Test5 t5 = new
Test5("HI");
}
}
a) Hai,Hi,Hi
b) Hai,Hi
c) Hi,Hi
d)Compiler Error
21. Which of the following are not a wrapper class?
a) String
b) Integer
c) StringBuffer
d) Boolean
22. Select the correct syntax for main method :
a) public void main(String args[])
b) public static void main(String args)
c) public static void Main(String args[])
d) None of the Above
23 . Which of the following are not a valid declarations?
a) float f = 1;
b) float f = 1.2f;
c) float f = 1.2;
d) float f = (float)1.2;
24. What will be the output of the following program?
String s1 = new String("hi");
String s2 = "hi";
System.out.println(s1
==s2);
System.out.println(s1.equals(s2));
a) false true
b) true false
c) true true
d)None of the above.
25. What will be the output of the following program?
Integer i = new Integer(0);
Float f = new
Float(0);
System.out.println(i==f);
System.out.println(i.equals(f));
a) true false
b) false true
c) true true
d) Compiler error
No comments:
Post a Comment