0

programming languages Online Quiz - 43

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

How many key-value pairs will the hash contain? my %hash = ( [1, 2] => 1, [1, 2] => 2 );

  1. 1

  2. 2

  3. 3

  4. 4


Correct Option: B

What gets printed? package A; sub new { my $class = shift; my $self = {}; $self->init(); return bless $self, $class; }; sub init { my $self = shift; $self->{key} = 'value'; } sub get { my ($self, $key) = @_; return $self->{$key}; } package main; my $obj = A->new(); print $obj->get('key'), "\n";

  1. empty string

  2. value

  3. the code will fail

  4. None of the above


Correct Option: C

: What will be the size of the @fields array? my $record = ':a:b:c:'; my @fields = split(':', $record, -1);

  1. 0

  2. 1

  3. 3

  4. 5


Correct Option: D

What will be printed?my @a = (1, undef, 2);my $sum = 0;foreach my $val (@a) { eval { $sum += foo($val); }; if ($@) { $sum += 100; }}print "$sum\n";sub foo { my $val = shift; die "I don't like undefs" unless defined $val; return $val + $val;}

  1. 2

  2. 6

  3. 106

  4. I don't like undefs


Correct Option: C

What will be the value of $keys after execution of the following code? my $var; if (exists $var->{key1}->{key2}) { $var->{key1}->{key2} = 1; } my $keys = keys(%{$var});

  1. undef

  2. 0

  3. 1

  4. 2

  5. code will fail


Correct Option: C

What will be printed? BEGIN { print 'a'; } END { print 'b'; } BEGIN { print 'c'; } END { print 'd'; }

  1. abcd

  2. acbd

  3. cadb

  4. code will fail


Correct Option: C

What will be printed by the code below? my @a = (0, 1, 2); my ($b) = @a; print $b;

  1. 0

  2. 1

  3. 0 1 2

  4. 2

  5. 3


Correct Option: A

What is the output for the below code ? class A implements Runnable{ public void run(){ System.out.println(Thread.currentThread().getName()); } } 1. public class Test { 2. public static void main(String... args) { 3. A a = new A(); 4. Thread t = new Thread(a); 5. t.setName("good"); 6. t.start(); 7. } 8. }

  1. good

  2. null

  3. Compilation fails with an error at line 5

  4. Compilation succeed but Runtime Exception


Correct Option: A

What is the output for the below code ? public class Test { public static void main(String[] args) { List list = new ArrayList(); list.add(0, 59); int total = list.get(0); System.out.println(total); } }

  1. 59

  2. Compile time error, because you have to do int total = ((Integer)(list.get(0))).intValue();

  3. Compile time error, because can't add primitive type in List.

  4. Compile Properly but Runtime Exception


Correct Option: A

What is the output for the below code ? public class Test { public static void main(String[] args) { Integer i = null; int j = i; System.out.println(j); } }

  1. 0

  2. Compile with error

  3. null

  4. NullPointerException


Correct Option: A

What is the output for the below code ? public class Outer { private int a = 7; class Inner { public void displayValue() { System.out.println("Value of a is " + a); } } } public class Test { public static void main(String... args) throws Exception { Outer mo = new Outer(); Outer.Inner inner = mo.new Inner(); inner.displayValue(); } }

  1. Value of a is 7

  2. Compile Error - not able to access private member.

  3. Runtime Exception

  4. Value of a is 8


Correct Option: A

What is the output for the below code ? public class B { public String getCountryName(){ return "USA"; } public StringBuffer getCountryName(){ StringBuffer sb = new StringBuffer(); sb.append("UK"); return sb; } public static void main(String[] args){ B b = new B(); System.out.println(b.getCountryName().toString()); } }

  1. Compile with error

  2. USA

  3. UK

  4. Runtime Exception


Correct Option: A

What is the output for the below code ? public class C { } public class D extends C{ } public class A { public C getOBJ(){ System.out.println("class A - return C"); return new C(); } } public class B extends A{ public D getOBJ(){ System.out.println("class B - return D"); return new D(); } } public class Test { public static void main(String... args) { A a = new B(); a.getOBJ(); } }

  1. Compile with error - Not allowed to override the return type of a method with a subtype of the original type.

  2. class A - return C

  3. class B - return D

  4. Runtime Exception


Correct Option: C

What is the output for the below code ? import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String... args) { Pattern p = Pattern.compile("a*b"); Matcher m = p.matcher("b"); boolean b = m.matches(); System.out.println(b); } }

  1. true

  2. compile error

  3. false

  4. b


Correct Option: A

What is the output for the below code ? public class Test { public static void main(String... args) { String input = "1 fish 2 fish red fish blue fish"; Scanner s = new Scanner(input).useDelimiter("\s*fish\s*"); System.out.println(s.nextInt()); System.out.println(s.nextInt()); System.out.println(s.next()); System.out.println(s.next()); s.close(); } }

  1. 1 2 red blue

  2. Compile Error - because Scanner is not defind in java.

  3. 1 fish 2 fish red fish blue fish

  4. 1 fish 2 fish red blue fish


Correct Option: A
Explanation:

To solve this question, the user needs to understand how the Scanner class works in Java and how the useDelimiter() method works.

The useDelimiter() method sets the delimiter pattern for the Scanner object to use when breaking down input into tokens. In this case, the delimiter pattern is set to "\s*fish\s*", which means that the Scanner object will split the input string whenever it encounters the word "fish" surrounded by any number of whitespace characters.

The code then uses the nextInt() and next() methods of the Scanner object to retrieve the tokens that were split from the input string.

Let's go through each option to determine the correct answer:

A. 1 2 red blue: This option is correct. The first call to nextInt() retrieves the integer "1" that comes before the first occurrence of "fish". The second call to nextInt() retrieves the integer "2" that comes after the first occurrence of "fish". The first call to next() retrieves the word "red", and the second call to next() retrieves the word "blue".

B. Compile Error - because Scanner is not defined in java.: This option is incorrect. The Scanner class is defined in Java, so this code will not produce a compile error due to the use of Scanner.

C. 1 fish 2 fish red fish blue fish: This option is incorrect. The code does not print out the entire input string, but rather it retrieves specific tokens from the input string using the nextInt() and next() methods.

D. 1 fish 2 fish red blue fish: This option is incorrect. The second call to nextInt() retrieves the integer "2", which comes after the first occurrence of "fish". The first call to next() retrieves the word "red", and the second call to next() retrieves the word "blue".

Therefore, the correct answer is:

The Answer is: A. 1 2 red blue

Flex is used for the development of Rich Internet Application which can also be deployed in

  1. Desktop

  2. Browsers

  3. Operating systems

  4. All the above


Correct Option: D

What are the languages the flex can be developed?

  1. ActionScript

  2. MXML

  3. HTML

  4. None of the above


Correct Option: A,B

Is it possible to make httpService Requests synchronous

  1. True

  2. False


Correct Option: B
- Hide questions