Java Programming Fundamentals Quiz
Test your knowledge of Java programming concepts including object-oriented design, exception handling, type casting, operators, loops, and data types. Also includes some COBOL programming questions.
Questions
"WRITE MASTER-REC INVALID KEY GO TO PARA-ERROR. Indicate which of the following are not valid modes of opening the INDEXED file of which MASTER-REC is a record."
- a and b
- a and c
- c and d
- a and d
"What do you think the output of the following code snippet will be? 01 WS-NUM-TEST PIC +9(2).99. 01 WS-NUM-TEST2 PIC -9(2).99. MOVE 19.99 TO WS-NUM-TEST MOVE -9.99 TO WS-NUM-TEST2 IF WS-NUM-TEST > WS-NUM-TEST2 DISPLAY ""+VE GREATER THAN -VE"" ELSE DISPLAY ""+VE LESS THAN -VE"" END-IF "
- +VE GREATER THAN -VE
- +VE LESS THAN -VE
- Compile error
- Edited Numeric field cannot be used for comparison.
public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12? (Choose three.)
- final
- static
- native
- public
- private
- abstract
Given: 10. public class Bar { 11.static void foo(int...x) { 12. // insert code here 13. } 14. } Which two code fragments, inserted independently at line 12, will allow the class to compile? (Choose two.)
- foreach(x) System.out.println(z);
- for(int z : x) System.out.println(z);
- while( x.hasNext()) System.out.println( x.next());
- for( int i=0; i< x.length; i++ ) System.out.println(x[i]);
Given: 11. public class Test { 12. public static void main(String [] args) { 13. int x =5; 14. boolean b1 = true; 15. boolean b2 = false; 16. 17.if((x==4) && !b2) 18. System.out.print(”l “); 19. System.out.print(”2 “); 20. if ((b2 = true) && b1) 21. System.out.print(”3 “); 22. } 23. } What is the result?
- 2
- 3
- 1 2
- 2 3
- 1 2 3
- Compilation fails.
- Given: 31. // some code here 32. try { 33. // some code here 34. } catch (SomeException se) { 35. // some code here 36. } finally { 37. // some code here 38. } Under which three circumstances will the code on line 37 be executed? (Choose three.)
- The instance gets garbage collected.
- The code on line 33 throws an exception.
- The code on line 35 throws an exception.
- The code on line 31 throws an exception.
- The code on line 33 executes successfully.
Given: 10. interface Foo {} 11. class Alpha implements Foo { } 12. class Beta extends Alpha {} 13. class Delta extends Beta { 14. public static void main( String[] args) { 15. Beta x = new Beta(); 16. // insert code here 17. } 18. } Which code, inserted at line 16, will cause a java.lang.ClassCastException?
- Alpha a = x;
- Foo f= (Delta)x;
- Foo f= (Alpha)x;
- Beta b = (Beta)(Alpha)x;
What will be the output of the below code snippet? public class Quiz1{ public static void main(String args[]) { System.out.print("H" + "a"); System.out.print('H' + 'a'); } }
- HaHa
- Ha169
- Ha Ha
- 169Ha
What will be the output of the below code snippet? public class Quiz2 { public static void main(String args[]) { String letters = "ABC"; char[] numbers = { '1', '2', '3' }; System.out.println(letters + " easy as " + numbers); } }
- ABC easy as [C@3e25a5
- ABC easy as 123
- ABC easy as 1 2 3
- ABC easy as 1,2,3
What will be the output of the below code snippet? public class Quiz3 { public static void main(String args[]) { final String pig = "length: 10"; final String dog = "length: " + pig.length(); System.out.println("Animals are equal: " + pig == dog); } }
- True
- False
What will be the output of the below code snippet? public class Quiz4 { public static void main(String args[]) { int j = 0; for (int i = 0; i < 100; i++) j = j++; System.out.println(j); } }
- 99
- 0
- 100
- 101
What will be the output of the below code snippet? public class Quiz5 { public static void main(String args[]) { int i = 0; while (-1 << i != 0) i++; System.out.println(i); } }
- 32
- Infinite Loop
- 16
- 64
What will be the output of the below code snippet? public class Quiz6 { public static void main(String[] args) { System.out.println(decision()); } static boolean decision() { try { return true; } finally { return false; } } }
- True
- False
- Compilation Error
- Run Time Error
What will be the output of the below code snippet? public class Quiz7 { public static void main(String[] args) { try { System.out.println("Hello world"); System.exit(0); } finally { System.out.println("Goodbye world"); } } }
- Hello world \n Goodbye world
- Hello world
- Compilation Error
- Run Time Error
What will be the output of the below code snippet? public class Quiz8 { class Base { public String className = "Base"; } class Derived extends Base { private String className = "Derived"; } public static void main(String[] args) { System.out.println(new Derived().className); } }
- Derived
- Compilation Error in Main mehod
- Compilation Error due to Derived class
- Run Time Error
What will be the output of the below code snippet? public class Quiz9 { public static void main(String args[]) { int j = 0; for (int i = 0; i < 100; i++) j++; System.out.println(j); } }
- 99
- 100
- 0
- 101
What will be the output of the below code snippet? public class Quiz10 { public static void main(String args[]) { System.out.println((int) (char) (byte) -1); } }
- 65536
- 65535
- 1
- -1
Given: 20. public class CreditCard { 21. 22. private String cardlD; 23. private Integer limit; 24. public String ownerName; 25. 26. public void setCardlnformation(String cardlD, 27. String ownerName, 28. Integer limit) { 29. this.cardlD = cardlD; 30. this.ownerName = ownerName; 31. this.limit = limit; 32. } 33. }
- The class is fully encapsulated.
- The code demonstrates polymorphism.
- The ownerName variable breaks encapsulation
- The cardlD and limit variables break polymorphism.
Which Man class properly represents the relationship “Man has a best friend who is a Dog”?
- class Man extends Dog { }
- class Man implements Dog { }
- class Man { private BestFriend dog; }
- class Man { private Dog bestFriend; }
- class Man { private Dog<bestFriend> }
- class Man { private BestFriend<dog> }
Which statements about JDBC are true?
- JDBC is an API to connect to relational-, object- and XML data sources
- JDBC stands for Java DataBase Connectivity
- JDBC is an API to access relational databases, spreadsheets and flat files
- JDBC is an API to bridge the object-relational mismatch between OO programs and relational