1. Find the given file. package com.concretepage; public class A extends B { public static void main(String[] args) { Short myNum = 7; System.out.println(add(myNum, 6)); } } class B { int add(int x, int y) { return x + y; } } What is the result?
2. What is the output for the below code? public class A { int add(int i, int j){ return i+j; } } public class B extends A{ public static void main(String argv[]){ short s = 9; System.out.println(add(s,6)); } }
3. class A { A(String s) { } A() { } } 1. class B extends A { 2. B() { } 3. B(String s) { 4. super(s); 5. } 6. void test() { 7. // insert code here 8. } 9. } Which of the below code can be insert at line 7 to make clean compilation?
4. What is the output for the below code ? public class A { int k; boolean istrue; static int p; public void printValue() { System.out.print(k); System.out.print(istrue); System.out.print(p); } } public class Test{ public static void main(String argv[]){ A a = new A(); a.printValue(); } }
5. Find the given file. package com.concretepage; public class Computer implements Device{ public void doIt() { } } abstract class Phone1 extends Computer { } abstract class Phone2 extends Computer{ public void doIt(int x) { } } class Phone3 extends Computer implements Device{ public void doStuff() { } } interface Device { public void doIt(); } What is the result?
6. Method which follows JavaBeans standard?
7. What will be the result of compiling the following code: public class SuperClass { public int doIt(String str, Integer… data)throws Exception{ String signature = “(String, Integer[])”; System.out.println(str + ” ” + signature); return 1; } } public class SubClass extends SuperClass{ public int doIt(String str, Integer… data) { String signature = “(String, Integer[])”; System.out.println(“Overridden: ” + str + ” ” + signature); return 0; } public static void main(String… args) { SuperClass sb = new SubClass(); sb.doIt(“hello”, 3); } }
8. What is the output for the below code? public class Test { public static void main(String[] args){ String value = “abc”; changeValue(value); System.out.println(value); } public static void changeValue(String a){ a = “xyz”; } }
9. ou have two class files name Test.class and Test1.class inside javaproject directory. Test.java source code is: public class Test{ public static void main (String[] args){ System.out.println(“Hello Test”); } } Test1.java source code is : public class Test1{ public static void main (String[] args){ System.out.println(“Hello Test1″); } } you have issued below commands from command prompt. cd javaproject java Test Test1 What is the output?
10. Find the given file. package com.concretepage; class Road { public static void main(String[] args) { for(int __x = 0; __x < 3; __x++) ; int #lb = 7; long [] x [5]; Boolean []ba[]; } enum Traffic { RED, YELLOW, GREEN }; } What is the result?
11. What is the output for the below code? public class A { static{System.out.println(“static”);} { System.out.println(“block”);} public A(){ System.out.println(“A”); } public static void main(String[] args){ A a = new A(); } }
12. What is the output for the below code? interface A { public void printValue(); } 1. public class Test{ 2. public static void main (String[] args){ 3. A a1 = new A() { 4. public void printValue(){ 5. System.out.println(“A”); 6. } 7. }; 8. a1.printValue(); 9. } 10. }
13. Find the given file. package com.concretepage; enum Day { MON("1"), TUE("2"), WED("3"); String s; Day(String s) { this.s = s; } } public class Test { static Day d; public static void main(String[] args) { System.out.println(d.MON.s + " " + d.TUE.s); } } What is the result?
14. What is the output for the below code? public class A { public void printName(){ System.out.println(“Value-A”); } } public class B extends A{ public void printName(){ System.out.println(“Name-B”); } } public class C extends A{ public void printName(){ System.out.println(“Name-C”); } } 1. public class Test{ 2. public static void main (String[] args) { 3. B b = new B(); 4. C c = new C(); 5. b = c; 6. newPrint(b); 7. } 8. public static void newPrint(A a){ 9. a.printName(); 10. } 11. }
15. Choose the correct statement.
16. Find the given file. package com.concretepage; public class Test { public enum Days { MON, TUE, WED, THU }; public static void main(String[] args) { for(Days d : Days.values() ); Days [] d2 = Days.values(); System.out.println(d2[3]); } } What is the result?
17. What is the output for the below code? public class A { int i = 10; public void printValue() { System.out.println(“Value-A”); } } public class B extends A{ int i = 12; public void printValue() { System.out.print(“Value-B”); } } public class Test{ public static void main(String argv[]){ A a = new B(); a.printValue(); System.out.println(a.i); } }
18. try{ File f = new File(“a.txt”); }catch(Exception e){ }catch(IOException io){ } Is this code create new file name a.txt?
19. What is the output for the below code? 1. public class Test { 2. public static void main(String[] args){ 3. byte b = 6; 4. b+=8; 5. System.out.println(b); 6. b = b+7; 7. System.out.println(b); 8. } 9. }
20. What is the output for the below code? public class C { } public class D extends C{ } public class A { public C getOBJ(){ System.out.println(“class A – return C”); return new C(); } } public class B extends A{ public D getOBJ(){ System.out.println(“class B – return D”); return new D(); } } public class Test { public static void main(String… args) { A a = new B(); a.getOBJ(); } }