programming languages Online Quiz - 150

Test your knowledge of multiple programming languages including Perl and Java, covering syntax, variables, operators, control structures, and object-oriented concepts.

13 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What results from the following code? 1. class MyClass 2. { 3. void myMethod(int i) {System.out.println("int version");} 4. void myMethod(String s) {System.out.println("String version");} 5. public static void main(String args[]) 6. { 7. MyClass obj = new MyClass(); 8. char ch = 'c'; 9. obj.myMethod(ch); 10. } 11. }

  1. The code compiles and produces output: int version.
  2. Line 9 will not compile as there is no version of myMethod which takes a char as argument.
  3. An exception at line 9.
  4. Line 4 will not compile as void methods can't be overridden.
Question 2 Multiple Choice (Single Answer)

What is the result when you compile and run the following code? public class ThrowsDemo { static void throwMethod() { System.out.println("Inside throwMethod."); throw new IllegalAccessException("demo"); } public static void main(String args[]) { try { throwMethod(); } catch (IllegalAccessException e) { System.out.println("Caught " + e); } } }

  1. Compile successfully, nothing is printed
  2. Runtime error
  3. Compilation error
  4. Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo
Question 3 Multiple Choice (Single Answer)

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); } }

  1. 0122
  2. 0123
  3. Compilation error
  4. None of these
Question 4 Multiple Choice (Single Answer)

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); } }

  1. 0122
  2. 0123
  3. Compilation error
  4. None of these
Question 5 Multiple Choice (Single Answer)

What will be printed when you execute the following code? class X { Y b = new Y(); X() { System.out.print("X"); } } class Y { Y() { System.out.print("Y"); } } public class Z extends X { Y y = new Y(); Z() { System.out.print("Z"); } public static void main(String[] args) { new Z(); } }

  1. z
  2. yz
  3. xyz
  4. yxyz
Question 6 Multiple Choice (Single Answer)

What will be printed? use strict; my @a = (1, 2, 3); my %b = (2 => undef); for my $val (@a) { last if $b{$val}; } print $val;

  1. undef
  2. 0
  3. 1
  4. 2
  5. the code is ill-formed
Question 7 Multiple Choice (Single Answer)

What will be the value of $str after execution of the following code? my $str = '112133'; $str =~ s/(.)\1/$1/g;

  1. 112133
  2. 1233
  3. 1213
  4. 12133
Question 8 Multiple Choice (Single Answer)

my $val = 'x'; print ref($val); What is the output?

  1. SCALAR
  2. empty value
  3. STRING
  4. not a reference
Question 9 Multiple Choice (Single Answer)

What is the value of $match? my $txt = 'I am learning Perl'; my ($match) = $txt =~ /\s(.*)\s/;

  1. am learning
  2. I am learning Perl
  3. learning
  4. am
  5. none
Question 10 Multiple Choice (Single Answer)

The $_ variable

  1. holds the last pattern matched.
  2. holds the output field separator.
  3. identifies the current command line argument.
  4. none of the above is correct.
Question 11 Multiple Choice (Single Answer)

What is Perl?

  1. Practical Extraction and Report Language
  2. Practice for Exclusive and Report Language
  3. Practical Extraction and Report Learning
  4. Practical Exclusive and Report Language
Question 12 Multiple Choice (Single Answer)

The value of the expression $yards += 10

  1. is 10
  2. is true.
  3. cannot be determined from the information given.
  4. relies on which command line arguments were used.
Question 13 Multiple Choice (Single Answer)

Which of the following commands will turn a scalar ($str)into an array of characters?

  1. @a = split($str).
  2. @a = split(/\s/, $str).
  3. This task can be done in Perl but none of the above commands do it.
  4. @a = split(/./, $str).