Java and COBOL Programming Fundamentals
Test your knowledge of Java and COBOL programming languages including operators, control structures, data types, and language-specific features.
Questions
"01 WS-VAR1 PIC X(10) VALUE 'ABCDEFGHIJ'. 01 WS-VAR2 REDEFINES WS-VAR1 PIC 9(5) VALUE '12345' DISPLAY WS-VAR1 WS-VAR2. What will be the result?"
- ABCDEFGHIJ 12345
- Data Exception error
- Compilation error
- 12345FGHIJ 12345
What is the maximum length of a field you can define using COMP-1?
- 10
- 18
- 17
- 12
"05 X PIC 99 VALUE 10. SUBTRACT 20 FROM X. DISPLAY X The result would be?"
- 1}
- It will give error
- 10
- -10
"77 WS-AMT PIC ZZZ999. ADD 100 TO WS-AMT WILL RESULT IN?"
- COMPILATION ERROR
- SOC7
- WS-AMT+100
- SOC4
"What will be the output of the following snippet: MOVE ZERO TO WS-COUNT IF WS-COUNT = 0 CONTINUE END-IF ADD +1 TO WS-COUNT. DISPLAY 'VALUE OF WS-COUNT: ' WS-COUNT "
- VALUE OF WS-COUNT: 0
- VALUE OF WS-COUNT: 1
- Compile error
- None of the above
"What will be the output of the following snippet: MOVE ZERO TO WS-COUNT IF WS-COUNT = 0 NEXT SENTENCE END-IF ADD +1 TO WS-COUNT. DISPLAY 'VALUE OF WS-COUNT: ' WS-COUNT "
- VALUE OF WS-COUNT: 0
- VALUE OF WS-COUNT: 1
- Compile error
- None of the above
The "switch" selection structure must end with the default case.
- True
- False
What will happen when you attempt to compile and run the following code? int Output = 10; boolean b1 = false; if((b1 == true) && ((Output += 10) == 20)) { System.out.println("We are equal " + Output); } else { System.out.println("Not equal! " + Output); }
- Compilation error, attempting to perform binary comparison on logical data type.
- Compilation and output of "We are equal 10".
- Compilation and output of "Not equal! 20".
- Compilation and output of "Not equal! 10".
What results from attempting to compile and run the following code? public class Ternary { public static void main(String args[]) { int a = 5; System.out.println("Value is - " + ((a < 5) ? 9.9 : 9)); } }
- prints: Value is - 9
- prints: Value is - 5
- Compilation error
- None of these
What is the result when you compile and run the following code? public class Test { public void method() { for(int i = 0; i < 3; i++) { System.out.print(i); } System.out.print(i); } }
- 0122
- 0123
- Compilation error
- None of these
What will be the output on compiling/running the following code? public class MyThread implements Runnable { String myString = "Yes "; public void run() { this.myString = "No "; } public static void main(String[] args) { MyThread t = new MyThread(); new Thread(t).start(); for (int i=0; i < 10; i++) System.out.print(t.myString); } }
- Compilation Error
- Prints : Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes and so on.
- Prints : No No No No No No No No No No and so on.
- Prints : Yes No Yes No Yes No Yes No Yes No and so on.
- The Output cannot be determined.
we Can create multiple objects of a single class.
- True
- False
The modulus operator (%) in Java can be used only with variables of integer type.
- True
- False
Declarations must appear at the start of the body of a Java method.
- True
- False
Whenever the "&&" operator is used, such as in: exp1 && exp2 where exp1 and exp2 are boolean expressions, both the boolean expressions are not always evaluated.
- True
- False
What is displayed when the following code is compiled and executed? String s1 = new String("Test"); String s2 = new String("Test"); if (s1==s2) System.out.println("Same"); if (s1.equals(s2)) System.out.println("Equals");
- Same Equals
- Equals
- Same
- The code compiles, but nothing is displayed upon execution.
- The code fails to compile.
- What will be the output of the following program?package chapters.chap02;public class Chap02 { public static void main(String[] args) { for (int i=0; i<5; i++){ switch (i){ case 0: System.out.println("0"); ++i; break; case -1: System.out.println("-1"); break; case 2: System.out.println("2"); i++; case 4: System.out.println("4"); break; } } }}
- The program will not stop and it will run recursively upon execution
- The program will output '0 2 5 5'.
- The program will output '0 2 4 4'.
- The program will output '02 4 5'.
- What will be the output of the following program when it is made to run with the options "java scjp5_0.chap07.Ques01 1"package scjp5_0.chap07;public class Ques01 { public static void main(String[] args) { for (int i = 0; i < 2; i ++){ try{ System.out.println(args[i]); }catch(Exception e){} } }}
- The program will output 'scjp5_0.chap07.Ques01 1'.
- The program will output 1.
- The program will output '1' and then will raise an ArrayIndexOutOfBoundsException.
- The program won't print anything but will raise an ArrayIndexOutOfBoundsException at run-time.
- How can you call one constructor from another if a class has multiple constructors
- Cant do
- use this ()
- new keyword
- using objectname
- What is the result of compiling and running the following code? class VarArgOne { public static void printArgs(String s, Integer ... i, String s) { //line 1 for(int j : i) { //line 2 System.out.print(j + " " + s); //line 3 } } public static void main(String ... args) { //line 4 printArgs("exam", 12, 34, "scjp"); //line 5 } }
- Compilation fails due to error at line 1.
- Compilation fails due to error at line 2.
- Compilation fails due to error at line 4.
- Compilation fails due to error at both line 1 and line 4.