Consider below codes of 3 java files:
1. //M.java
2. package com.sampleproject.oca;
3.
4. public class M {
5. public void printName() {
6. System.out.println("M");
7. }
8. }
1. //N.java
2. package com.sampleproject.oca;
3.
4. public class N extends M {
5. public void printName() {
6. System.out.println("N");
7. }
8. }
1. //Test.java
2. package com.sampleproject.oca.test;
3.
4. import com.sampleproject.oca.*;
5.
6. public class Test {
7. public static void main(String[] args) {
8. M obj1 = new M();
9. N obj2 = (N)obj1;
10. obj2.printName();
11. }
12. }
What will be the result of compiling and executing Test class?
Given code:
package com.udayan.oca;
public class Test {
public static void main(String[] args) {
/*INSERT*/
arr[1] = 5;
arr[2] = 10;
System.out.println("[" + arr[1] + ", " + arr[2] + "]"); //Line n1
}
}
And below statements:
1. short arr [] = new short[2];
2. byte [] arr = new byte[10];
3. short [] arr; arr = new short[3];
4. short [2] arr;
5. short [3] arr;
6. int [] arr = new int[]{100, 100};
7. int [] arr = new int[]{0, 0, 0, 0};
8. short [] arr = {};
9. short [] arr = new short[2]{5, 10};
How many above statements can be used to replace /*INSERT*/, such that on execution, code will print [5, 10] on to the console?
What will be the result of compiling and executing Test class?
package com.udayan.oca;
public class Test {
public static void main(String[] args) {
m1(null);
}
static void m1(CharSequence s) {
System.out.println("CharSequence");
}
static void m1(String s) {
System.out.println("String");
}
static void m1(Object s) {
System.out.println("Object");
}
}
Given the code fragment:
Consider below code of Test.java file:
1. package com.sampleproject.oca;
2.
3. public class Test {
4. public static void main(String[] args) {
5. String [][] arr = { {"%", "$$"}, {"***", "@@@@", "#####"}};
6. for(String [] str : arr) {
7. for(String s : str) {
8. System.out.println(s);
9. if(s.length() == 4) //Line n1
10. break; //Line n2
11. }
12. break; //Line n3
13. }
14. }
15. }
What will be the result of compiling and executing Test class?
© Copyrights Oracledumps 2025. All Rights Reserved
We use cookies to ensure that we give you the best experience on our website (Oracledumps). If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the Oracledumps.