Quiz Java (Sanyamjain 1803010192)
Quiz Java (Sanyamjain 1803010192)
Roll No - 1803010192
Arrays
Answer : C
Answer : D
Answer : D
Answer : A
Answer :A
1. class array_output
2. {
3. public static void main(String args[])
4. {
5. int array_variable [] = new int[10];
6. for (int i = 0; i < 10; ++i)
7. {
8. array_variable[i] = i;
9. System.out.print(array_variable[i] + " ");
10. i++;
11. }
12. }
13. }
a) 0 2 4 6 8
b) 1 3 5 7 9
c) 0 1 2 3 4 5 6 7 8 9
d) 1 2 3 4 5 6 7 8 9 10
Answer : A
1. class multidimention_array
2. {
3. public static void main(String args[])
4. {
5. int arr[][] = new int[3][];
6. arr[0] = new int[1];
7. arr[1] = new int[2];
8. arr[2] = new int[3];
9. int sum = 0;
10. for (int i = 0; i < 3; ++i)
11. for (int j = 0; j < i + 1; ++j)
12. arr[i][j] = j + 1;
13. for (int i = 0; i < 3; ++i)
14. for (int j = 0; j < i + 1; ++j)
15. sum + = arr[i][j];
16. System.out.print(sum);
17. }
18. }
a) 11
b) 10
c) 13
d) 14
Answer :B
1. class evaluate
2. {
3. public static void main(String args[])
4. {
5. int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
6. int n = 6;
7. n = arr[arr[n] / 2];
8. System.out.println(arr[n] / 2);
9. }
10. }
a) 3
b) 0
c) 6
d) 1
Answer :D
1. class array_output
2. {
3. public static void main(String args[])
4. {
5. char array_variable [] = new char[10];
6. for (int i = 0; i < 10; ++i)
7. {
8. array_variable[i] = 'i';
9. System.out.print(array_variable[i] + "");
10. }
11. }
12. }
a) 1 2 3 4 5 6 7 8 9 10
b) 0 1 2 3 4 5 6 7 8 9 10
c) i j k l m n o p q r
d) i i i i i i i i i I
Answer :D
1. class array_output
2. {
3. public static void main(String args[])
4. {
5. int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8,
9}};
6. int sum = 0;
7. for (int i = 0; i < 3; ++i)
8. for (int j = 0; j < 3 ; ++j)
9. sum = sum + array_variable[i][j];
10. System.out.print(sum / 5);
11. }
12. }
a) 8
b) 9
c) 10
d) 11
Answer : B
Loops
1. What would be the output of the following code snippet if variable a=10?
1. if(a<=0)
2. {
3. if(a==0)
4. {
5. System.out.println("1 ");
6. }
7. else
8. {
9. System.out.println("2 ");
10. }
11. }
12. System.out.println("3 ");
a) 1 2
b) 2 3
c) 1 3
d) 3
Answer : B
2. The while loop repeats a set of code while the condition is not met?
a) True
b) False
Answer :B
Answer : B
Answer : A
6. What is the valid data type for variable “a” to print “Hello World”?
1. switch(a)
2. {
3. System.out.println("Hello World");
4. }
a) int and float
b) byte and short
c) char and long
d) byte and char
Answer : A
Answer : D
Answer : B
Answer : D
Answer : A
1. What is the process of defining two or more methods within same class that have same name
but different parameters declaration?
a) method overloading
b) method overriding
c) method hiding
d) none of the mentioned
Answer : A
Answer : C
Answer : A
4. What is the process of defining a method in terms of itself, that is a method that calls itself?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion
Answer : D
1. class San
2. {
3. public void m1 (int i,float f)
4. {
5. System.out.println(" int float method");
6. }
7.
8. public void m1(float f,int i);
9. {
10. System.out.println("float int method");
11. }
12.
13. public static void main(String[]args)
14. {
15. San s=new San();
16. s.m1(20,20);
17. }
18. }
a) int float method
b) float int method
c) compile time error
d) run time error
Answer : C
1. class overload
2. {
3. int x;
4. int y;
5. void add(int a)
6. {
7. x = a + 1;
8. }
9. void add(int a, int b)
10. {
11. x = a + 2;
12. }
13. }
14. class Overload_methods
15. {
16. public static void main(String args[])
17. {
18. overload obj = new overload();
19. int a = 0;
20. obj.add(6);
21. System.out.println(obj.x);
22. }
23. }
a) 5
b) 6
c) 7
d) 8
Answer : C
1. class overload
2. {
3. int x;
4. int y;
5. void add(int a)
6. {
7. x = a + 1;
8. }
9. void add(int a , int b)
10. {
11. x = a + 2;
12. }
13. }
14. class Overload_methods
15. {
16. public static void main(String args[])
17. {
18. overload obj = new overload();
19. int a = 0;
20. obj.add(6, 7);
21. System.out.println(obj.x);
22. }
23. }
a) 6
b) 7
c) 8
d) 9
Answer : C
1. class overload
2. {
3. int x;
4. double y;
5. void add(int a , int b)
6. {
7. x = a + b;
8. }
9. void add(double c , double d)
10. {
11. y = c + d;
12. }
13. overload()
14. {
15. this.x = 0;
16. this.y = 0;
17. }
18. }
19. class Overload_methods
20. {
21. public static void main(String args[])
22. {
23. overload obj = new overload();
24. int a = 2;
25. double b = 3.2;
26. obj.add(a, a);
27. obj.add(b, b);
28. System.out.println(obj.x + " " + obj.y);
29. }
30. }
a) 6 6
b) 6.4 6.4
c) 6.4 6
d) 4 6.4
Answer : D
Answer : A
1. class test
2. {
3. int a;
4. int b;
5. test(int i, int j)
6. {
7. a = i;
8. b = j;
9. }
10. void meth(test o)
11. {
12. o.a *= 2;
13. O.b /= 2;
14. }
15. }
16. class Output
17. {
18. public static void main(String args[])
19. {
20. test obj = new test(10 , 20);
21. obj.meth(obj);
22. System.out.println(obj.a + " " + obj.b);
23. }
24. }
a) 10 20
b) 20 10
c) 20 40
d) 40 20
Answer : B
EJB
Answer : A
Answer : B
Answer : A
4. Which of the following is correct error when loading JAR file with duplicate name?
a) java.io.NullPointerException
b) java.lang.ClassNotFound
c) java.lang.ClassFormatError
d) java.lang.DuplicateClassError
Answer : C
Answer : B
7. What is the attribute of java bean to specify scope of bean to have single instance per Spring
IOC?
a) prototype
b) singleton
c) request
d) session
Answer : B
Answer : B
Answer : A