0% found this document useful (0 votes)
76 views

Quiz Java (Sanyamjain 1803010192)

This document contains the name, roll number, and answers to 10 multiple choice questions related to arrays in Java by Sanyam Jain. It also contains answers to 10 additional multiple choice questions related to loops in Java.

Uploaded by

faltu bhai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Quiz Java (Sanyamjain 1803010192)

This document contains the name, roll number, and answers to 10 multiple choice questions related to arrays in Java by Sanyam Jain. It also contains answers to 10 additional multiple choice questions related to loops in Java.

Uploaded by

faltu bhai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Name : SANYAM JAIN

Roll No - 1803010192
Arrays

1. Which of these operators is used to allocate memory to array variable in Java?


a) malloc
b) alloc
c) new
d) new malloc

Answer : C

2. Which of these is an incorrect array declaration?


a) int arr[] = new int[5]
b) int [] arr = new int[5]
c) int arr[] = new int[5]
d) int arr[] = int [5] new

Answer : D

3. What will be the output of the following Java code?

int arr[] = new int [5];


System.out.print(arr);
a) 0
b) value stored in arr[0]
c) 00000
d) Class name@ hashcode in hexadecimal form

Answer : D

4.Which of these is an incorrect Statement?


a) It is necessary to use new operator to initialize an array
b) Array can be initialized using comma separated expressions surrounded by curly braces
c) Array can be initialized when they are declared
d) None of the mentioned

Answer : A

5.Which of these is necessary to specify at time of array initialization?


a) Row
b) Column
c) Both Row and Column
d) None of the mentioned

Answer :A

6. What will be the output of the following Java code?

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

7. What will be the output of the following Java code?

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

8. What will be the output of the following Java code?

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

9. What will be the output of the following Java code?

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

10. What will be the output of the following Java code?

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

3. What is true about a break?


a) Break stops the execution of entire program
b) Break halts the execution and forces the control out of the loop
c) Break forces the control out of the loop and starts the execution of next iteration
d) Break halts the execution of the loop for certain time frame

Answer : B

4. What is true about do statement?


a) do statement executes the code of a loop at least once
b) do statement does not get execute if condition is not matched in the first iteration
c) do statement checks the condition at the beginning of the loop
d) do statement executes the code more than once always

Answer : A

3. Which of the following is used with the switch statement?


a) Continue
b) Exit
c) break
d) do
Answer : C

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

7. Which of the following is not a decision making statement?


a) if
b) if-else
c) switch
d) do-while

Answer : D

8. Which of the following is not a valid jump statement?


a) break
b) goto
c) continue
d) return

Answer : B

9. From where break statement causes an exit?


a) Only from innermost loop
b) Terminates a program
c) Only from innermost switch
d) From innermost loops or switches

Answer : D

10. Which of the following is not a valid flow control statement?


a) exit()
b) break
c) continue
d) return

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

2. Which of these can be overloaded?


a) Methods
b) Constructors
c) All of the mentioned
d) None of the mentioned

Answer : C

3. Which of these is correct about passing an argument by call-by-value process?


a) Copy of argument is made into the formal parameter of the subroutine
b) Reference to original argument is passed to formal parameter of the subroutine
c) Copy of argument is made into the formal parameter of the subroutine and changes made on
parameters of subroutine have effect on original argument
d) Reference to original argument is passed to formal parameter of the subroutine and changes
made on parameters of subroutine have effect on original argument

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

5. What will be the output of the following Java code?

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

6. What will be the output of the following Java code?

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

7. What will be the output of the following Java code?

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

8. What will be the output of the following Java code?

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

9. What will be the output of the following Java code?


1. class test
2. {
3. int a;
4. int b;
5. void meth(int i , int j)
6. {
7. i *= 2;
8. j /= 2;
9. }
10. }
11. class Output
12. {
13. public static void main(String args[])
14. {
15. test obj = new test();
16. int a = 10;
17. int b = 20;
18. obj.meth(a , b);
19. System.out.println(a + " " + b);
20. }
21. }
a) 10 20
b) 20 10
c) 20 40
d) 40 20

Answer : A

10. What will be the output of the following Java code?

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

1. Which of the following is not an Enterprise Beans type?


a) Doubleton
b) Singleton
c) Stateful
d) Stateless

Answer : A

2. Which of the following is not true about Java beans?


a) Implements java.io.Serializable interface
b) Extends java.io.Serializable class
c) Provides no argument constructor
d) Provides setter and getter methods for its properties

Answer : B

3. Which file separator should be used by MANIFEST file?


a) /
b) \
c) –
d) //

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

5. Java Beans are extremely secured?


a) True
b) False

Answer : B

6. Which of the following is not a feature of Beans?


a) Introspection
b) Events
c) Persistence
d) Serialization
Answer : D

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

8. Which attribute is used to specify initialization method?


a) init
b) init-method
c) initialization
d) initialization-method
Answer :B

9. Which attribute is used to specify destroy method?


a) destroy
b) destroy-method
c) destruction
d) destruction-method

Answer : B

10. How to specify autowiring by name?


a) @Qualifier
b) @Type
c) @Constructor
d) @Name

Answer : A

You might also like