0

programming languages Online Quiz - 327

Description: programming languages Online Quiz - 327
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

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

  1. 6

  2. 1

  3. 5

  4. Compiler error


Correct Option: B

AI Explanation

To find the output of the given program, let's go through each step:

  1. The variable i is initialized with a value of 5.
  2. The printf function is used to print the value of i=++i == 6.
  3. The expression ++i increments the value of i by 1 before it is used in the comparison.
  4. The comparison i == 6 checks if the incremented value of i is equal to 6.
  5. The result of the comparison is assigned to i.
  6. The printf function prints the value of i, which is the result of the comparison.

Now, let's analyze the expression i=++i == 6:

  1. The variable i is incremented by 1, so its new value is 6.
  2. The comparison 6 == 6 evaluates to true, which is represented by the value 1.
  3. The value 1 is assigned to i.

Therefore, the value of i is 1.

The correct answer is B) 1.

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.


Correct Option: A
  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


Correct Option: A

AI Explanation

To answer this question, we need to understand the different modifiers that can be used in a Java interface.

In a Java interface, the following modifiers can be used:

A) final: This modifier indicates that the value of the variable cannot be changed once it is assigned. It is valid to use the final modifier in an interface variable declaration. Therefore, option A is valid.

B) native: This modifier is used to indicate that a method is implemented in a language other than Java. It is not valid to use the native modifier in an interface variable declaration.

C) abstract: This modifier is used to indicate that a method or class does not have an implementation and must be implemented by a subclass. It is not valid to use the abstract modifier in an interface variable declaration.

D) protected: This modifier is used to indicate that a variable, method, or class can only be accessed within its own package or by a subclass of its class. It is not valid to use the protected modifier in an interface variable declaration.

Therefore, the three valid modifiers to use on line 12 are final.

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;


Correct Option: A

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.


Correct Option: A
  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


Correct Option: A

AI Explanation

To answer this question, let's go through each option:

Option A) final - This option is valid on line 12. The "final" keyword is used to indicate that a variable's value cannot be changed once it has been assigned a value. In this case, the variable "MY_VALUE" is assigned the value 10, and since it is declared as "final", its value cannot be changed.

Option B) native - This option is not valid on line 12. The "native" keyword is used in the declaration of a method to indicate that the method's implementation will be provided by a native code, typically written in a language like C or C++. It is not applicable to variables.

Option C) abstract - This option is not valid on line 12. The "abstract" keyword is used to indicate that a class or method does not have an implementation and must be overridden by a subclass. It is not applicable to variables.

Option D) protected - This option is not valid on line 12. The "protected" keyword is used to specify that a member (variable or method) can only be accessed within its own package or by a subclass of its class. It is not applicable to variables.

Therefore, the three valid options on line 12 are A) final, C) and F) abstract.

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


Correct Option: D

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

  1. 6

  2. 1

  3. 5

  4. Compiler error


Correct Option: B

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


Correct Option: A

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

  1. 1000000

  2. Overflow

  3. None

  4. Error


Correct Option: C

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


Correct Option: B

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


Correct Option: B

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


Correct Option: A

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


Correct Option: A

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


Correct Option: D

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


Correct Option: A
  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


Correct Option: D

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’


Correct Option: B
- Hide questions