Special Offer! 20% OFF on All Certification Exam Questions - Ends In Coupon code: TEL20
Stay ahead with 100% Free Java SE 8 Programmer I 1Z0-808 Dumps Practice Questions
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?
Consider below code of Test.java file:
1. package com.sampleproject.oca;
2.
3. class Super {
4. public String num = "10"; //Line n1
5. }
6.
7. class Sub extends Super {
8. protected int num = 20; //Line n2
9. }
10.
11. public class Test {
12. public static void main(String[] args) {
13. Super obj = new Sub();
14. System.out.println(obj.num += 2); //Line n3
15. }
16. }
What will be the result of compiling and executing above code?
Given:
What will be the result of compiling and executing Test class?
1. package com.udayan.oca;
2.
3. public class Test {
4. public static void main(String[] args) {
5. int x = 1;
6. while(checkAndIncrement(x)) {
7. System.out.println(x);
8. }
9. }
10.
11. private static boolean checkAndIncrement(int x) {
12. if(x < 5) {
13. x++;
14. return true;
15. } else {
16. return false;
17. }
18. }
19. }
Below is the code of Test.java file:
1. package com.udayan.oca;
2.
3. import java.util.ArrayList;
4. import java.util.List;
5.
6. public class Test {
7. public static void main(String [] args) {
8. List
9.
10. list.add(27);
11. list.add(27);
12.
13. list.add(new Integer(27));
14. list.add(new Integer(27));
15.
16. System.out.println(list.get(0) == list.get(1));
17. System.out.println(list.get(2) == list.get(3));
18. }
19. }
What will be the result of compiling and executing Test class?
© Copyrights TheExamsLab 2025. All Rights Reserved
We use cookies to ensure your best experience. So we hope you are happy to receive all cookies on the TheExamsLab.