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.
Questions
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. }
- The code compiles and produces output: int version.
- Line 9 will not compile as there is no version of myMethod which takes a char as argument.
- An exception at line 9.
- Line 4 will not compile as void methods can't be overridden.
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); } } }
- Compile successfully, nothing is printed
- Runtime error
- Compilation error
- Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo
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 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 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(); } }
- z
- yz
- xyz
- yxyz
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;
- undef
- 0
- 1
- 2
- the code is ill-formed
What will be the value of $str after execution of the following code? my $str = '112133'; $str =~ s/(.)\1/$1/g;
- 112133
- 1233
- 1213
- 12133
my $val = 'x'; print ref($val); What is the output?
- SCALAR
- empty value
- STRING
- not a reference
What is the value of $match? my $txt = 'I am learning Perl'; my ($match) = $txt =~ /\s(.*)\s/;
- am learning
- I am learning Perl
- learning
- am
- none
The $_ variable
- holds the last pattern matched.
- holds the output field separator.
- identifies the current command line argument.
- none of the above is correct.
What is Perl?
- Practical Extraction and Report Language
- Practice for Exclusive and Report Language
- Practical Extraction and Report Learning
- Practical Exclusive and Report Language
The value of the expression $yards += 10
- is 10
- is true.
- cannot be determined from the information given.
- relies on which command line arguments were used.
Which of the following commands will turn a scalar ($str)into an array of characters?
- @a = split($str).
- @a = split(/\s/, $str).
- This task can be done in Perl but none of the above commands do it.
- @a = split(/./, $str).