Oca Java02
Oca Java02
QUESTION
1. package com.udayan.oca;
2. 4. QUESTION
3. public class Test {
4. char c; Fill in the blanks for the definition of
5. double d;
6. float f;
java.lang.Error class:
7. public static void main(String[] args) {
8. Test obj = new Test();
public class java.lang.Error extends ________________ {...}
9. System.out.println(">" + obj.c);
10. System.out.println(">" + obj.d);
11. System.out.println(">" + obj.f);
12. } A- RuntimeException
Throwable
13. }
B-
C- Exception
A- >null
>0.0
>0.0 5. QUESTION
B- > What will be the result of compiling and executing
>0.0 Test class?
>0.0f
C- > 1. package com.udayan.oca;
2.
>0.0 3. public class Test {
>0.0 4. public static void main(String[] args) {
5. String fruit = "mango";
D- >null 6. switch (fruit) {
>0.0 7. default:
8. System.out.println("ANY FRUIT WILL DO");
>0.0f 9. case "Apple":
10. System.out.println("APPLE");
11. case "Mango":
12. System.out.println("MANGO");
2. QUESTION 13. case "Banana":
14. System.out.println("BANANA");
For the class Test, which options, if used to 15. break;
replace /*INSERT*/, will print "Hurrah! I 16. }
17. }
passed..." on to the console? 18. }
6. QUESTION
What will be the result of compiling and executing
Test class?
1. package com.udayan.oca; 2.
2. 3. public class Test {
3. public class Test { 4. public static void main(String[] args) {
4. public static void main(String[] args) { 5. /*INSERT*/
5. String str = "java"; 6. switch(var) {
6. StringBuilder sb = new StringBuilder("java"); 7. case 7:
7. 8. System.out.println("Lucky no. 7");
8. System.out.println(str.equals(sb) + ":" + sb.equals(str)); 9. break;
9. } 10. default:
10. } 11. System.out.println("DEFAULT");
12. }
13. }
14. }
A- true:false
B- false:false A- char var = ‘7’;
C- true:true B- char var = 7;
D- false:true C- Character var ‘7’;
E- Compilation error D- Character var = 7;
E- Integer var 7;
7. QUESTION
Consider below code: 9. QUESTION
For the given code snippet:
1. //Test.java
2. package com.udayan.oca; List<String> list = new /*INSERT*/();
3.
4. import java.time.LocalDate; Which of the following options, if used to replace
5.
6. class MyLocalDate extends LocalDate { /*INSERT*/, compiles successfully?
7. @Override
8. public String toString() { A- List<>
9. return super.getDayOfMonth() + "-" + super.getMonthValue()
+
B- ArrayList<>
10. "-" + super.getYear(); C- ArrayList<String>
11. } D- List<String>
12. }
13.
14. public class Test {
15. public static void main(String [] args) {
16. MyLocalDate date = LocalDate.parse("1980-03-16"); 10. QUESTION
17. System.out.println(date); What will be the result of compiling and executing
18. }
19. } Test class?
1. package com.udayan.oca;
What will be the result of compiling and executing 2.
Test class? 3. public class Test {
4. private static void m(int x) {
5. System.out.println("int version");
A- Compilation error 6. }
B- 16-03-1980 7.
C- 16-3-1980 8. private static void m(char x) {
9. System.out.println("char version");
D- 1980-03-16 10. }
E- An exception is thrown at runtime 11.
12. public static void main(String [] args) {
13. int i = '5';
14. m(i);
15. m('5');
16. }
17. }
A- char version
int version
8. QUESTION B- char version
For the class Test, which options, if used to char version
replace /*INSERT*/, will print "Lucky no. 7" on C- Compilation error
to the console? Select 3 options. D- int version
char version
1. package com.udayan.oca;
2
E- int version Which of the following is a checked Exception?
int version
A- FileNotFoundException
B- RuntimeException
11. QUESTION C- ExceptionInInitializerError
D- ClassCastException
What will be the result of compiling and executing
Test class?
12. QUESTION
Consider the code of Test.java file: 15. QUESTION
What will be the result of compiling and executing
1. package com.udayan.oca; Test class?
2.
3. class Student {
1. package com.udayan.oca;
4. String name;
2.
5. int age;
3. import java.io.FileNotFoundException;
6.
4. import java.io.IOException;
7. void Student() {
5.
8. Student("James", 25);
6. abstract class Super {
9. }
7. public abstract void m1() throws IOException;
10.
8. }
11. void Student(String name, int age) {
9.
12. this.name = name;
10. class Sub extends Super {
13. this.age = age;
11. @Override
14. }
12. public void m1() throws IOException {
15. }
13. throw new FileNotFoundException();
16.
14. }
17. public class Test {
15. }
18. public static void main(String[] args) {
16.
19. Student s = new Student();
17. public class Test {
20. System.out.println(s.name + ":" + s.age);
18. public static void main(String[] args) {
21. }
19. Super s = new Sub();
22. }
20. try {
21. s.m1();
What will be the result of compiling and executing 22. } catch (FileNotFoundException e) {
23. System.out.print("M");
Test class? 24. } finally {
25. System.out.print("N");
A- James:25 26. }
27. }
B- null:0 28. }
C- An exception is thrown at runtime
D- Compilation error A- N
B- Compilation error
C- Program ends abruptly
13. QUESTION D- MN
3
16. QUESTION 1.
2.
//A.java
package com.udayan.oca;
What will be the result of compiling and executing 3.
4. public class A {
Test class? 5. public void print() {
6. System.out.println("A");
1. package com.udayan.oca; 7. }
2. 8. }
3. public class Test { 9.
4. public static void main(String[] args) { 10. //B.java
5. System.out.println("Output is: " + 10 != 5); 11. package com.udayan.oca;
6. } 12.
7. } 13. public class B extends A {
14. public void print() {
15. System.out.println("B");
A- Output is: false 16. }
B- Compilation error 17. }
C- Output is: true 18.
19. //Test.java
D- Output is: 10 != 5 20. package com.udayan.oca.test;
21.
22. import com.udayan.oca.*;
23.
17. QUESTION 24. public class Test {
25. public static void main(String[] args) {
What will be the result of compiling and executing 26. A obj1 = new A();
Test class? 27. B obj2 = (B)obj1;
28. obj2.print();
29. }
1. package com.udayan.oca; 30. }
2.
3. import java.util.function.Predicate;
4. What will be the result of compiling and executing
5. public class Test {
6. public static void main(String[] args) {
Test class?
7. String [] arr = {"A", "ab", "bab", "Aa", "bb", "baba", "aba", "A
bab"}; A- ClassCastException is thrown at runtime
8.
9. Predicate<String> p = s -> s.toUpperCase().substring(0,1).equals(
B- A
"A"); C- B
10. D- Compilation error
11. processStringArray(arr, p);
12. }
13.
14. private static void processStringArray(String [] arr, Predicate<Stri
ng> predicate) {
15. for(String str : arr) {
16. if(predicate.test(str)) {
17. System.out.println(str);
18. }
19. }
20. }
21. }
4
19. } Which of the following code correctly extracts
20. }
21. } country code from the swift code referred by
String reference variable swiftCode?
What will be the result of compiling and executing
Test class? A- swiftCode.substring(5, 7);
B- swiftCode.substring(4, 6);
A- VTEO
C- swiftCode.substring(5, 6);
B- VTE
C- VET D- swiftCode.substring(4, 5);
D- Compilation error
E- Runtime exception
F- VETO
22. QUESTION
What will be the result of compiling and executing
20. QUESTION Test class?
Given the code of Test.java file: 1. //Test.java
2. package com.udayan.oca;
1. package com.udayan.oca; 3.
2. 4. class Student {
3. class Point { 5. String name;
4. int x; 6. int marks;
5. int y; 7.
6. void assign(int x, int y) { 8. Student(String name, int marks) {
7. x = this.x; 9. this.name = name;
8. this.y = y; 10. this.marks = marks;
9. } 11. }
10. 12. }
11. public String toString() { 13. public class Test {
12. return "Point(" + x + ", " + y + ")"; 14. public static void main(String[] args) {
13. } 15. Student student = new Student("James", 25);
14. } 16. int marks = 25;
15. 17. review(student, marks);
16. public class Test { 18. System.out.println(marks + "-" + student.marks);
17. public static void main(String[] args) { 19. }
18. Point p1 = new Point(); 20.
19. p1.x = 10; 21. private static void review(Student stud, int marks) {
20. p1.y = 20; 22. marks = marks + 10;
21. Point p2 = new Point(); 23. stud.marks+=marks;
22. p2.assign(p1.x, p1.y); 24. }
23. System.out.println(p1.toString() + ";" + p2.toString()); 25. }
24. }
25. }
A- 35-25
B- 35-60
What will be the result of compiling and executing C- 25-25
Test class? D- 25-60
A bank's swift code is generally of 11 characters 6. public static void main(String[] args) {
7. System.out.println("HELLO");
and used in international money transfers. 8. }
An example of swift code: ICICINBBRT4 9. }
ICIC: First 4 letters for bank code
IN: Next 2 letters for Country code On execution, does Test class print "HELLO" on
BB: Next 2 letters for Location code to the console?
RT4: Next 3 letters for Branch code
A- Yes, HELLO is printed on to the console
5
B- No, HELLO is not printed on the console 9. package orders.items;
10.
11. public class Item {
12.
13. }
24. QUESTION 14.
15. //Shop.java
Consider below code: 16. package shopping;
17.
1. //Test.java 18. /*INSERT*/
2. package com.udayan.oca; 19.
3. 20. public class Shop {
4. import java.time.LocalDate; 21. Order order = null;
5. import java.time.LocalTime; 22. Item item = null;
6. 23. }
7. public class Test {
8. public static void main(String [] args) {
9. LocalDate date = LocalDate.parse("1947-08-14"); For the class Shop, which options, if used to
10. LocalTime time = LocalTime.MAX; replace /*INSERT*/, will resolve all the
11. System.out.println(date.atTime(time));
12. } compilation errors? Select 2 options.
13. }
A- import orders.items.*;
What will be the result of compiling and executing B-
Test class? 1. import orders.*;
2. import orders.items.*;
A- 1947-08-14T23:59:59.0 C-
1. import orders.Order;
B- 1947-08-14T23:59:59 2. import orders.items.Item;
import orders.*;
C- 1947-08-14T23:59:59.999 D-
D- 1947-08-14T23:59:59.999999999
E-
1. import orders.*;
2. import items.*;
25. QUESTION
Consider below code:
1. //Test.java
2. package com.udayan.oca; 27. QUESTION
3.
4. public class Test { Consider below code:
5. public static void main(String[] args) {
6. StringBuilder sb = new StringBuilder(100);
1. //Test.java
7. System.out.println(sb.length() + ":" + sb.toString().length());
2. package com.udayan.oca;
8. }
3.
9. }
4. public class Test {
5. public static void main(String[] args) {
What will be the result of compiling and executing 6. String s1 = "OCAJP";
7. String s2 = "OCAJP" + "";
Test class? 8. System.out.println(s1 == s2);
9. }
10. }
A- 0:0
B- 16:16
C- 100:100 What will be the result of compiling and executing
D- 16:0 Test class?
E- 100:0
A- false
B- OCAJP
26. QUESTION C- Compilation error
Consider 3 files:
1.
2.
//Order.java
package orders;
28. QUESTION
3. Consider below code:
4. public class Order {
5.
6. } 1. //Test.java
7. 2. package com.udayan.oca;
8. //Item.java 3.
6
4. import java.util.ArrayList; D- Happy Holidays!
5.
6. class Counter {
Happy Holidays!
7. int count;
8. Counter(int count) {
9. this.count = count;
10. } 30. QUESTION
11.
12. public String toString() { For the class Test, which options, if used to
13. return "Counter-" + count; replace /*INSERT*/, will print [5, 10] on to the
14. }
15. } console? Select 3 options.
16.
17. public class Test { 1. package com.udayan.oca;
18. public static void main(String[] args) { 2.
19. ArrayList<Counter> original = new ArrayList<>(); 3. public class Test {
20. original.add(new Counter(10)); 4. public static void main(String[] args) {
21. 5. /*INSERT*/
22. ArrayList<Counter> cloned = (ArrayList<Counter>) original.clo 6. arr[0] = 5;
ne(); 7. arr[1] = 10;
23. cloned.get(0).count = 5; 8. System.out.println("[" + arr[0] + ", " + arr[1] + "]");
24. 9. }
25. System.out.println(original); 10. }
26. }
27. }
A- short [] arr = {};
What will be the result of compiling and executing B- short [2] arr;
Test class? C- short [] arr = new short[2]{100, 100};
D- short [] arr = new short[]{100, 100};
A- An exception is thrown at runtime
B- [Counter-10]
C- Compilation error
D- [Counter-5]
E-
1. short [] arr;
2. arr = new short[2];
29. QUESTION F- short arr [] = new short[2];
What will be the result of compiling and executing
Test class?
1. package com.udayan.oca;
31. QUESTION
2. What will be the result of compiling and executing
3. class Message {
4. String msg = "Happy New Year!"; Test class?
5.
6. public void print() { 1. package com.udayan.oca;
7. System.out.println(msg); 2.
8. } 3. public class Test {
9. } 4. public static void main(String[] args) {
10. 5. Double [] arr = new Double[2];
11. public class Test { 6. System.out.println(arr[0] + arr[1]);
12. public static void change(Message m) { 7. }
13. m = new Message(); 8. }
14. m.msg = "Happy Holidays!";
15. }
16. A- 0.0
17. public static void main(String[] args) { B- Compilation error
18. Message obj = new Message(); C- NullPointerException is thrown at runtime
19. obj.print();
20. change(obj); D- ClassCastException is thrown at runtime
21. obj.print();
22. }
23. }
32. QUESTION
A- Happy New Year! Which of the following correctly defines class
Happy New Year! Printer?
B- Happy New Year!
Happy Holidays! A-
C- null
Happy New Year! 1. import java.util.*;
7
2.
3.
package com.udayan.oca;
public class Printer {
34. QUESTION
4. Consider below code:
5. }
1. //Test.java
B- 2. package com.udayan.oca;
3.
4. import java.time.LocalDate;
6. public class Printer {
5.
7. package com.udayan.oca;
6. public class Test {
8. }
7. public static void main(String [] args) {
8. LocalDate newYear = LocalDate.of(2018, 1, 1);
C- 9. LocalDate christmas = LocalDate.of(2018, 12, 25);
10. boolean flag1 = newYear.isAfter(christmas);
11. boolean flag2 = newYear.isBefore(christmas);
9. public class Printer { 12. System.out.println(flag1 + ":" + flag2);
10. 13. }
11. } 14. }
12. package com.udayan.oca;
D-
13. /* Java Developer Comments. */ What will be the result of compiling and executing
14. package com.udayan.oca; Test class?
15. public class Printer {
16.
17. } A- Compilation error
B- An exception is thrown at runtime
C- false:true
D- true:false
33. QUESTION
What will be the result of compiling and executing
Test class? 35. QUESTION
1. package com.udayan.oca;
____________ uses access modifiers to protect
2. variables and hide them within a class.
3. public class Test { Which of the following options accurately fill in
4. public static void main(String[] args) {
5. int x = 1; the blanks above?
6. while(checkAndIncrement(x)) {
7. System.out.println(x);
8. }
A- Encapsulation
9. } B- Abstraction
10. C- Polymorphism
11. private static boolean checkAndIncrement(int x) { D- Inheritance
12. if(x < 5) {
13. x++;
14. return true;
15. } else {
16. return false; 36. QUESTION
17. }
18. }
What will be the result of compiling and executing
19. } Test class?
A- 1 1. package com.udayan.oca;
2.
2 3. import java.time.LocalTime;
3 4.
4 5. public class Test {
6. public static void main(String[] args) {
B- Infinite loop
7. LocalTime time = LocalTime.of(16, 40);
C- 2 8. String amPm = time.getHour() >= 12 ? (time.getHour() == 12) ? "
3 PM" : "AM";
4 9. System.out.println(amPm);
10. }
5 11. }
D- 1
2 A- PM
3 B- AM
4 C- Compilation error
5 D- An exception is thrown at runtime
8
37. QUESTION 5.
6.
switch(var) {
case 100:
How many objects of Pen class are eligible for 7. System.out.println("var is 100");
8. break;
Garbage Collection at Line 4? 9. case 200:
10. System.out.println("var is 200");
1. package com.udayan.oca; 11. break;
2. 12. default:
3. class Pen { 13. System.out.println("In default");
4. 14. }
5. } 15. }
6. 16. }
7. public class TestPen {
8. public static void main(String[] args) {
9. new Pen(); //Line 1 A- var is 100
10. Pen p = new Pen(); // Line 2 B- In default
11. change(p); //Line 3 C- Compilation error
12. System.out.println("About to end."); //Line 4
13. } D- var is 200
14.
15. public static void change(Pen pen) { //Line 5
16. pen = new Pen(); //Line 6
17. } 40. QUESTION
18. }
Consider below code:
A- 0 1. //Test.java
B- 1 2. package com.udayan.oca;
C- 3 3.
D- 2 4. import java.time.LocalDateTime;
5.
6. public class Test {
7. public static void main(String [] args) {
8. LocalDateTime obj = LocalDateTime.now();
38. QUESTION 9. System.out.println(obj.getSecond());
10. }
What will be the result of compiling and executing 11. }
Test class?
Which of the following statement is correct?
1. import java.util.ArrayList;
2. import java.util.List;
3. A- Code fails to compile
4. public class Test {
B- It will print any int value between 1 and 60
5. public static void main(String[] args) {
6. List<Integer> list = new ArrayList<>(); C- Code compiles successfully but throws
7. list.add(100); Runtime exception
8. list.add(200); D- It will print any int value between 0 and 59
9. list.add(100);
10. list.add(200);
11. list.remove(100);
12.
13. System.out.println(list); 41. QUESTION
14. }
15. }
Which of these access modifiers can be used for a
top level interface?
A- [100, 200, 200]
A- All of the other options
B- [200]
B- protected
C- [200, 100, 200] C- public
D- Exception is thrown at runtime D- private
E- [200, 200]
42. QUESTION
39. QUESTION What will be the result of compiling and executing
What will be the result of compiling and executing the Test class?
Test class?
1. package com.udayan.oca;
2.
1. package com.udayan.oca; 3. public class Test {
2. public class Test { 4. public static void main(String[] args) {
3. public static void main(String[] args) { 5. int grade = 60;
4. byte var = 100; 6. if(grade = 60)
9
7. System.out.println("You passed...");
8. else
9. System.out.println("You failed...");
10. }
11. }
A- Compilation error
B- You passed…
C- Produces no output
D- You failed…
1. package com.udayan.oca;
What will be the result of compiling and executing
2. Test class?
3. public class Test {
4. public static void main(String[] args) {
5. double [] arr = new int[2]; //Line 3 A- An exception is thrown at runtime
6. System.out.println(arr[0]); //Line 4 B- Compilation error
7. } C- 2020-10-01
8. }
D- 2020-09-30
A- 0.0
B- Line 3 causes compilation error
C- 0 47. QUESTION
D- Line 4 causes runtime exception
10
What will be the result of compiling and executing 15. }
Test class?
What will be the result of compiling and executing
1. //Test.java Test class?
2. package com.udayan.oca.test;
3.
4. abstract class Animal { A- 01-11-11
5. private String name; B- 11-11-11
6.
7. Animal(String name) {
C- 11-11-12
8. this.name = name; D- Runtime exception
9. } E- 01-11-12
10.
11. public String getName() {
12. return name;
13. }
14. } 49. QUESTION
15. Consider below code:
16. class Dog extends Animal {
17. private String breed;
18. Dog(String breed) { 1. //Test.java
19. this.breed = breed; 2. package com.udayan.oca;
20. } 3.
21. 4. class SpecialString {
22. Dog(String name, String breed) { 5. String str;
23. super(name); 6. SpecialString(String str) {
24. this.breed = breed; 7. this.str = str;
25. } 8. }
26. 9. }
27. public String getBreed() { 10.
28. return breed; 11. public class Test {
29. } 12. public static void main(String[] args) {
30. } 13. System.out.println(new String("Java"));
31. 14. System.out.println(new StringBuilder("Java"));
32. public class Test { 15. System.out.println(new SpecialString("Java"));
33. public static void main(String[] args) { 16. }
34. Dog dog1 = new Dog("Beagle"); 17. }
35. Dog dog2 = new Dog("Bubbly", "Poodle");
36. System.out.println(dog1.getName() + ":" + dog1.getBreed() + ":" + d
og2.getName() + ":" + dog2.getBreed()); What will be the result of compiling and executing
37. } Test class?
38. }
A- Java
A- Compilation error for Animal Class Java
B- null:Beagle:Bubbly:Poodle Java
C- Compilation error for Dog(String) constructor B- Java
D- :Beagle:Bubbly:Poodle Java
E- Compilation error for Dog(String, String) <Some text containing @ symbol>
constructor C- Compilation error
F- Compilation error for Animal(String) D- Java
constructor <Some text containing @ symbol>
<Some text containing @ symbol>
48. QUESTION
Consider below code: 50. QUESTION
Consider below code:
1. //Test.java
2. package com.udayan.oca;
3. 1. //Test.java
4. import java.time.LocalDate; 2. package com.udayan.oca;
5. import java.time.Period; 3. import java.util.ArrayList;
6. import java.time.format.DateTimeFormatter; 4. import java.util.List;
7. 5.
8. public class Test { 6. public class Test {
9. public static void main(String [] args) { 7. public static void main(String[] args) {
10. LocalDate date = LocalDate.of(2012, 1, 11); 8. String s = new String("Hello");
11. Period period = Period.ofMonths(2); 9. List<String> list = new ArrayList<>();
12. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM- 10. list.add(s);
dd-yy"); 11. list.add(new String("Hello"));
13. System.out.print(formatter.format(date.minus(period))); 12. list.add(s);
14. } 13. s.replace("l", "L");
11
14.
15. System.out.println(list);
16. }
17. }
53. QUESTION
What will be the result of compiling and executing
What will be the result of compiling and executing
Test class?
Test class?
A- [HeLLo, Hello, HeLLo] 1. package com.udayan.oca;
B- [HeLLo, Hello, Hello] 2.
C- [HeLLo, HeLLo, HeLLo] 3. public class Test {
4. public static void main(String[] args) {
D- [Hello, Hello, Hello] 5. short [] args = new short[]{50, 50};
6. args[0] = 5;
7. args[1] = 10;
8. System.out.println("[" + args[0] + ", " + args[1] + "]");
51. QUESTION 9. }
10. }
What will be the result of compiling and executing
Test class? A- An exception is thrown at runtime
B- [5, 10]
1. package com.udayan.oca;
2. C- Compilation error
3. public class Test { D- [50, 50]
4. public static void main(String[] args) {
5. String [] fruits = {"apple", "banana", "mango", "orange"};
6. for(String fruit : fruits) {
7.
8.
System.out.print(fruit + " ");
if(fruit.equals("mango")) {
54. QUESTION
9. continue; Which of the following statement is correct about
10. }
11. System.out.println("salad!"); below code?
12. break;
13. } 1. public class Test {
14. } 2. public static void main(String[] args) {
15. } 3. do {
4. System.out.println(100);
5. } while (false);
A- apple banana orange salad! 6. System.out.println("Bye");
B- apple salad! 7. }
8. }
C- apple banana mango salad!
D- None of the other options. A- 100
Bye
B- Unreachable code compilation error
52. QUESTION C- Compiles successfully and prints 100 in
infinite loop
What will be the result of compiling and executing D- Compiles successfully and prints "Bye"
Test class?
1. package com.udayan.oca;
2. 55. QUESTION
3. public class Test {
4. public static void main(String[] args) { Below is the code of Test.java file:
5. StringBuilder sb = new StringBuilder("Java");
6. String s1 = sb.toString(); 1. import java.util.ArrayList;
7. String s2 = sb.toString(); 2. import java.util.List;
8. 3.
9. System.out.println(s1 == s2); 4. public class Test {
10. } 5. public static void main(String [] args) {
11. } 6. List<Integer> list = new ArrayList<Integer>();
7. list.add(new Integer(2));
A- Compilation error 8. list.add(new Integer(1));
9. list.add(new Integer(0));
B- false 10.
C- An exception is thrown at runtime 11. list.remove(list.indexOf(0));
D- true 12.
13. System.out.println(list);
14. }
15. }
12
What will be the result of compiling and executing A- Student[James, 27]
Test class? Student[James, 25]
Student[James, 25]
A- An exception is thrown at runtime B- Student[James, 27]
B- Compilation error C- Student[James, 25]
C- [1, 0] Student[James, 27]
D- [2, 1] Student[James, 25]
D- Student[James, 25]
Student[James, 27]
Student[James, 25]
56. QUESTION Student[James, 25]
What will be the result of compiling and executing
Test class?
58. QUESTION
1. public class Test {
2. public static void main(String [] args) { Given code:
3. int a = 100;
4. System.out.println(-a++); 1. package com.udayan.oca;
5. } 2.
6. } 3. public class Test {
4. public static void main(String[] args) {
A- -100 5. String [] arr = {"A", "B", "C", "D", "E"};
6. for(/*INSERT*/) {
B- 99 7. System.out.print(arr[n]);
C- Compilation error 8. }
D- -101 9. }
10. }
E- -99
1. //Test.java
2. package com.udayan.oca;
3.
4. import java.util.ArrayList;
5. import java.util.Iterator;
6. import java.util.List;
7. import java.util.function.Predicate;
8.
9. class Employee {
10. private String name;
11. private int age;
12. private double salary;
13. 62. QUESTION
14. public Employee(String name, int age, double salary) {
15. this.name = name; Consider below code:
16. this.age = age;
17. this.salary = salary; 1. import java.util.ArrayList;
18. } 2. import java.util.List;
19. 3.
20. public String getName() { 4. public class Test {
21. return name; 5. public static void main(String[] args) {
22. } 6. List<String> list1 = new ArrayList<>();
23. 7. list1.add("A");
24. public int getAge() { 8. list1.add("D");
25. return age; 9.
26. } 10. List<String> list2 = new ArrayList<>();
27. 11. list2.add("B");
14
12. list2.add("C"); Consider the following class:
13.
14. list1.addAll(1, list2);
15. 1. public class Employee {
16. System.out.println(list1); 2. public int passportNo; //line 2
17. } 3. }
18. }
A- [1919-02-25, 1980-12-31]
A- Compilation error B- [2018-07-11, 2020-04-08]
B- ArrayIndexOutOfBoundsException is thrown C- Runtime exception
at runtime D- [2018-07-11, 1919-02-25, 2020-04-08, 1980-
C- 0 12-31]
1
2
D- 2
1 69. QUESTION
0 What will be the result of compiling and executing
Test class?
70. QUESTION
Consider below code:
17