0

programming languages Online Quiz - 2

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

Method-Overloading implements the principle of Compile-time Polymorphism, wheras Method Over-riding implements the concept of Runtime Polymorphism.

  1. True

  2. False


Correct Option: B

JVM is the compiler for Java.

  1. True

  2. False


Correct Option: B

How many objects are created in the below code...????

String s="abc";  
String s1=new String("def");
  1. 1 Object

  2. 2 Objects

  3. 3 Objects

  4. 4 Objects


Correct Option: C

What is the concept Below???

class A  {
    int x=10;
};

class B extends A  {
    int x=100;
    show()     {
        System.out.println(x);
    }
    public static void main(String... s)  {
        B b1=new B();
        b1.show();
    }
};

The program will print 100. But the concept illustrated is----

  1. Data Shadowing

  2. Data Over-riding

  3. Data Obscuring

  4. None of the Above


Correct Option: D

What is the output??(Easy One)

String s1="Java";
String s2="Java";
String s3=new String("Java");
String s4=new String("Java");
if(s1==s2)  System.out.print("true");
else  System.out.println("false");
if(s3==s4)  System.out.print("true");
else  System.out.println("false");
if(s1==s3)  System.out.print("true");
else  System.out.println("false");
if(s2==s3.intern())  System.out.print("true");
else  System.out.println("false");
if(s3.intern()==s2.intern())  System.out.print("true");
else  System.out.println("false");

Just try and get the Ouput---(Ignore any errors)

  1. true false true false true

  2. true false false true true

  3. true false false false true

  4. true false true false false


Correct Option: B

AI Explanation

To determine the output of the given code, let's go through each line step by step:

String s1 = "Java";
String s2 = "Java";
String s3 = new String("Java");
String s4 = new String("Java");

In the above code, s1 and s2 are string literals, while s3 and s4 are objects created using the new keyword.

if(s1 == s2)
    System.out.print("true");
else
    System.out.println("false");

Here, s1 and s2 are both string literals, and they refer to the same object in the string pool. So, the condition s1 == s2 is true, and "true" is printed.

if(s3 == s4)
    System.out.print("true");
else
    System.out.println("false");

In this case, s3 and s4 are two different objects created using the new keyword, so the condition s3 == s4 is false, and "false" is printed.

if(s1 == s3)
    System.out.print("true");
else
    System.out.println("false");

Here, s1 is a string literal and s3 is an object created using the new keyword. They are not the same object, so the condition s1 == s3 is false, and "false" is printed.

if(s2 == s3.intern())
    System.out.print("true");
else
    System.out.println("false");

The intern() method returns the canonical representation of a string object from the string pool. In this case, s3 is interned and refers to the same object as s2. So, the condition s2 == s3.intern() is true, and "true" is printed.

if(s3.intern() == s2.intern())
    System.out.print("true");
else
    System.out.println("false");

Since both s3 and s2 are interned and refer to the same object in the string pool, the condition s3.intern() == s2.intern() is true, and "true" is printed.

Therefore, the output of the given code is:

B. true false false true true

Variables are not interpolated inside which operator when used normally?

  1. " "

  2. < >

  3. ' '

  4. / /


Correct Option: C

The regex /g.d?c*/ doesn't match

  1. godccc

  2. gddd

  3. goc

  4. gc


Correct Option: B

What is the outcome of the scenario on Unix platform: open(FH, "&gt;c:\temp\notes.txt") ?

  1. Opens a file notes.txt

  2. fails to create a file and displays error

  3. fails to open a file but doesn't display error

  4. Opens a file but not notes.txt


Correct Option: D

$a=[ { name=&gt; "rose", kids=&gt; [ qw( ted bobby john ) ] }, { name=&gt; "marge", kids=&gt; [ qw( maggie lisa bart ) } ]

  1. A list of hashes which contains a list

  2. A hash of hashes which contains a list

  3. A list of list which contains another list

  4. A list of arrays and hashes containing lists


Correct Option: A

What happens when @_ is modified?

  1. when arrays and references are passed

  2. only when references are passed

  3. args are not changed

  4. Command line args are changed


Correct Option: D

%abc = %\$def which option is correct when $def = \%any_hash ?

  1. all key value pairs are copied but in random order

  2. all key value pairs are copied in proper order

  3. all key value pairs from def may not be copied into abc

  4. syntax error


Correct Option: A

what is the output for printf ("%06.2f", \$amt) when \$amt = 9.355 ?

  1. 9.3550

  2. 9.4

  3. 009.40

  4. Error


Correct Option: C

($t, @u, $v, @w ) = qw( India US Japan Spain Mexico China ). How many elements are assigned to @u,@w?

  1. 1 and 2

  2. 5 and 0

  3. 1 and 3

  4. none of the above


Correct Option: B

Out of below four cases

  1. -5+5
  2. " "
  3. 0X0
  4. "0.00" + 0
  1. 1 and 4

  2. 2 and 4

  3. 3 and 1

  4. 2 and 3


Correct Option: A

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) 1 and 4 - This option is correct because both -5+5 and "0.00" + 0 can be evaluated to produce a valid result. -5+5 equals 0, and "0.00" + 0 equals "0.00" (a string concatenation).

Option B) 2 and 4 - This option is incorrect because the expression " " is an empty string and cannot be evaluated to produce a valid result. Therefore, option 2 is incorrect.

Option C) 3 and 1 - This option is incorrect because the expression 0X0 is not a valid mathematical expression. It appears to be a typo or incorrect format for multiplication. Therefore, option 3 is incorrect.

Option D) 2 and 3 - This option is incorrect because, as explained earlier, the expression " " is an empty string and cannot be evaluated to produce a valid result. Therefore, option 2 is incorrect.

The correct answer is option A. This option is correct because both -5+5 and "0.00" + 0 can be evaluated to produce valid results.

  1. &complex_num();
  2. complex_num();

which is correct?

  1. 1 can only be called with predecleration of complex_num

  2. 1 and 2 are same

  3. 2 can only be called with predecleration of complex_num

  4. 1 is reference to a subroutine


Correct Option: C

Can we use the constructor, instead of init(), to initialize servlet?

  1. Yes

  2. No

  3. May Be

  4. Can't Say


Correct Option: A

Which of the following should NOT be used to share data between servlets in a distributed web application?

  1. Attributes of ServletContext

  2. Enterprise Java Beans

  3. Attributes of HttpSession

  4. Database


Correct Option: A

AI Explanation

To answer this question, you need to understand the different ways of sharing data between servlets in a distributed web application.

Option A) Attributes of ServletContext - This option is incorrect because ServletContext attributes can be used to share data between servlets in a distributed web application. ServletContext is a global object that is accessible to all servlets running within the same web application.

Option B) Enterprise Java Beans (EJB) - This option is incorrect because EJBs can be used to share data between servlets in a distributed web application. EJBs are a server-side component model in Java EE that provides a way to write reusable and scalable business logic.

Option C) Attributes of HttpSession - This option is incorrect because HttpSession attributes can be used to share data between servlets in a distributed web application. HttpSession is an object that represents a user session and can store data that is specific to that session.

Option D) Database - This option is incorrect because a database can be used to share data between servlets in a distributed web application. Servlets can store and retrieve data from a database to share information between different components of the application.

The correct answer is A) Attributes of ServletContext. This option is incorrect because ServletContext attributes can be used to share data between servlets in a distributed web application.

Can we call destroy() method on servlets from service method ?

  1. Yes

  2. No

  3. May be

  4. Cant Say


Correct Option: A

Which jsp implicit object is synchronized?

  1. session

  2. page

  3. application

  4. None of the above


Correct Option: B

Can we implement an interface in JSP ?

  1. Yes

  2. No

  3. May be

  4. Cant say


Correct Option: B
- Hide questions