Programming Languages Quiz: C, Java, and RPG

Test your knowledge across multiple programming languages including C, Java, and RPG (IBM AS/400). Covers file I/O, memory allocation, operators, interfaces, inheritance, and system-specific operations.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Find the output of this program. main() { int i=5; printf(“%d”,i=++i ==6); }

  1. 6
  2. 1
  3. 5
  4. Compiler error
Question 2 Multiple Choice (Multiple Answers)

Question 3 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?

  1. D. 2 3
  2. A. 2 B. 3
  3. C. 1 2 E. 1 2 3
  4. F. Compilation fails. G. Au exceptional is thrown at runtime.
Question 3 Multiple Choice (Multiple Answers)
  1. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12? (Choose three.)
  1. A. final
  2. C. native
  3. F. abstract
  4. G. protected
Question 4 Multiple Choice (Multiple Answers)

Question 5 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?

  1. B. Foo f= (Delta)x;
  2. A. Alpha a = x;
  3. D. The code on line 31 throws an exception.
  4. C. Foo f= (Alpha)x; D. Beta b = (Beta)(Alpha)x;
Question 5 Multiple Choice (Multiple Answers)

Question 3 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?

  1. D. 2 3
  2. A. 2 B. 3
  3. C. 1 2 E. 1 2 3
  4. F. Compilation fails. G. Au exceptional is thrown at runtime.
Question 6 Multiple Choice (Multiple Answers)
  1. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12? (Choose three.)
  1. A. final
  2. C. native
  3. F. abstract
  4. G. protected
Question 7 Multiple Choice (Multiple Answers)

Question 5Given: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 here17. }18. }Which code, inserted at line 16, will cause ajava.lang.ClassCastException?

  1. B. Foo f= (Delta)x;
  2. A. Alpha a = x;
  3. D. The code on line 31 throws an exception.
  4. C. Foo f= (Alpha)x; D. Beta b = (Beta)(Alpha)x;
Question 8 Multiple Choice (Single Answer)

Find the output of this program. main() { int a[10]; printf("%d",*a+1-*a+3) ; }

  1. Compiler error
  2. 3
  3. -2
  4. 4
Question 9 Multiple Choice (Single Answer)

Find the output of this program. main() { int i=5; printf(“%d”,i=++i ==6); }

  1. 6
  2. 1
  3. 5
  4. Compiler error
Question 10 Multiple Choice (Single Answer)

Find the output of this program. main() { int i=0; while(+(+i--)!=0) i-=i++; printf("%d",i); }

  1. -1
  2. 1
  3. 0
  4. Compiler error
Question 11 Multiple Choice (Single Answer)

Find the output of this program. void main(){ float j; j=1000*1000; printf("%f",j); }

  1. 1000000
  2. Overflow
  3. None
  4. Error
Question 12 Multiple Choice (Single Answer)

Which of the following is used to allocate memory to a program at run time?

  1. ALLOCATE
  2. ALLOC
  3. ALLMEM
  4. LOADM
  5. None of the above
Question 13 Multiple Choice (Single Answer)

Which of the following is the operation code extender for not locking a record on a READ or CHAIN?

  1. L
  2. N
  3. E
  4. P
  5. none of the above
Question 14 Multiple Choice (Single Answer)

Given a full procedural, externally-described input file named ORDER with a record length of 41 bytes, which of the following is a valid format for the File specification for the ORDER file?

  1. A. FORDER IF E DISK
  2. B. FORDER IPE F 41 DISK
  3. C. FORDER IF E 41 DISK
  4. D. FORDER IF F DISK
Question 15 Multiple Choice (Single Answer)

Given a full procedural, externally-described input file named ORDER with a record length of 41 bytes, which of the following is a valid format for the File specification for the ORDER file?

  1. A. FORDER IF E DISK
  2. B. FORDER IPE F 41 DISK
  3. C. FORDER IF E 41 DISK
  4. D. FORDER IF F DISK
Question 16 Multiple Choice (Single Answer)

What type of object stores spooled files that are waiting to be printed on an output device?

  1. *SPLQ
  2. *PRTQ
  3. *PRTF
  4. *OUTQ
Question 17 Multiple Choice (Single Answer)

Given the following code, what is the value of RESULT? DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++ D RESULT S 5 0 CL0N01Factor1+++++++Opcode&ExtExtended-factor2+++++++++++++++++ C EVAL RESULT = (2 + 3 * 2) * 2 / 2

  1. 8
  2. 10
  3. 32
  4. 50
Question 18 Multiple Choice (Single Answer)

If the last record of a file has been read, and the next operation on that file is a READ operation, what will be the values of the input fields for that file?

  1. They will be blank and/or zero.
  2. They will be null.
  3. They will equal the values of the first record in the file.
  4. They will equal the values of the last record read
Question 19 Multiple Choice (Single Answer)

Given the DOS Specification below and the following information: • Indicator 50 is off • No records have been written to the subfile What will be the result if the EXFMT operation code is performed on the record format CTLR? A R SUBFL A DESCRIP 101 6 1ODSPATR(UL) A DFT(’NOT FOUND’) A R CTLR SFLCTL(SUBFL) A N50 SFLDSP A SFLDSPCTL A SFLINZ A 67 SFIJEND A SFLSIZ(13) A SFLPAG(12) A ACCOUNTNO 100 S 10

  1. Only AccountNo will display
  2. SUBFL will be initialized with 13 blank records
  3. An I/O exception error will occur
  4. The screen will display 12 records with ‘NOT FOUND’
Question 20 Multiple Choice (Single Answer)

Given the DOS Specification below and the following information: • Indicator 50 is off • No records have been written to the subfile What will be the result if the EXFMT operation code is performed on the record format CTLR? A R SUBFL A DESCRIP 101 6 1ODSPATR(UL) A DFT(’NOT FOUND’) A R CTLR SFLCTL(SUBFL) A N50 SFLDSP A SFLDSPCTL A SFLINZ A 67 SFIJEND A SFLSIZ(13) A SFLPAG(12) A ACCOUNTNO 100 S 10

  1. Only AccountNo will display
  2. SUBFL will be initialized with 13 blank records
  3. An I/O exception error will occur
  4. The screen will display 12 records with ‘NOT FOUND’