0

programming languages Online Quiz - 25

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

public class Test { public static void main(String... args) { for(int i = 2; i < 4; i++) for(int j = 2; j < 4; j++) if(i < j) assert i!=j : i; } }

  1. The class compiles and runs, but does not print anything

  2. The number 2 gets printed with AssertionError

  3. The number 3 gets printed with AssertionError

  4. compile error


Correct Option: A

What is the output for the below code ? public interface TestInf { int i =10; } public class Test { public static void main(String... args) { TestInf.i=12; System.out.println(TestInf.i); } }

  1. Compile with error

  2. 10

  3. 12

  4. Runtime Exception


Correct Option: A

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

  1. Compile with error

  2. 5

  3. 0

  4. Runtime Exception


Correct Option: A
  1. r1 r4 pre b1 b2 r3 r2 post

  2. r1 r4 pre b1 b2 post

  3. r1 r4 pre b1 b2 post r3 r2

  4. pre r1 r4 b1 b2 r2 r3 post


Correct Option: A
Explanation:

To understand the output of the given code, the user needs to know about the order of initialization of static and non-static blocks, constructors, and the concept of inheritance.

When the main method is executed, the following sequence of events will occur:

  1. The static block of class B will be executed first. It will print "r1 r4".

  2. The static block of class C will not be executed because it is not defined.

  3. The print statement inside the main method will execute and print "pre".

  4. A new object of class C is created using the default constructor.

  5. Since class C extends class B, the constructor of class B will be called first.

  6. Before the constructor of class B is called, the non-static block of class A will be executed. It will print "b1".

  7. The constructor of class B will be executed next. It will print "b2" and "r2".

  8. Before the constructor of class C is called, the non-static block of class B will be executed. It will print "r3".

  9. The constructor of class C will be executed last. It will not print anything.

  10. After the constructor of class C is called, the print statement inside the main method will execute and print "post".

Therefore, the output will be:

The Answer is: A) r1 r4 pre b1 b2 r3 r2 post

What is the output for the below code ? public class Test { public static void main(String... args) throws Exception { Integer i = 34; int l = 34; if(i.equals(l)){ System.out.println(true); }else{ System.out.println(false); } } }

  1. true

  2. false

  3. Compile Error

  4. Runtime Exception


Correct Option: A

Two methods with the same name but with different parameters?

  1. Overloading

  2. Overriding

  3. Overridable

  4. Duplexing


Correct Option: A
  1. it must inherit the properties of the interface

  2. contain the same methods as the interface

  3. create an interface object

  4. all of the above


Correct Option: D

What are the features of an abstract class?

  1. It contain instance variables

  2. It contain constructors

  3. It may extend another class

  4. All of the these


Correct Option: D
  1. It is allocated at compile time

  2. Declaration and initialization is separated

  3. It is allocated at runtime

  4. All of these


Correct Option: A
  1. No return type for events

  2. Double

  3. Integer

  4. String


Correct Option: A
Explanation:

To answer this question, the user needs to have knowledge about programming events. In programming, an event is an action or occurrence detected by a program, and it can have a return type.

Now, let's go through each option and explain why it is right or wrong:

A. No return type for events: This option is incorrect because events can have a return type. The return type defines what kind of value the event handler method returns when the event is raised.

B. Double: This option is incorrect because the return type of an event depends on the type of data that the event is passing. An event can have a return type of any valid data type, including Double, Integer, String, and others.

C. Integer: This option is incorrect because the return type of an event depends on the type of data that the event is passing. An event can have a return type of any valid data type, including Double, Integer, String, and others.

D. String: This option is incorrect because the return type of an event depends on the type of data that the event is passing. An event can have a return type of any valid data type, including Double, Integer, String, and others.

The Answer is: A. No return type for events

int keyword targets to which .Net type?

  1. System.Int8

  2. System.Int16

  3. System.Int32

  4. System.Int64


Correct Option: C
  1. Convert.ToString() handle null values but ToString() don't

  2. ToString() output as per format supplied

  3. Convert.ToString() only handle null values

  4. ToString() handle null values but Convert.ToString() don't


Correct Option: A
  1. a interger type to double

  2. a reference type to a value type

  3. a value type to a reference type

  4. a double type to interger


Correct Option: C

Different ways a method can be overloaded in C#.NET?

  1. Different parameter data types

  2. Different number of parameters

  3. Different order of parameters

  4. All of these


Correct Option: D

AI Explanation

To answer this question, we need to understand method overloading in C#. Method overloading allows us to define multiple methods with the same name but with different parameters. This enables us to perform different operations based on the arguments passed to the method.

Let's go through each option to understand why it is correct or incorrect:

Option A) Different parameter data types - This option is correct. Method overloading can be achieved by having methods with the same name but with different parameter data types. For example:

void Print(int num)
{
    // Do something with an integer parameter
}

void Print(string text)
{
    // Do something with a string parameter
}

Option B) Different number of parameters - This option is correct. Method overloading can also be achieved by having methods with the same name but with a different number of parameters. For example:

void Sum(int num1, int num2)
{
    // Do something with two integer parameters
}

void Sum(int num1, int num2, int num3)
{
    // Do something with three integer parameters
}

Option C) Different order of parameters - This option is correct. Method overloading can be achieved by having methods with the same name but with a different order of parameters. For example:

void Calculate(int num1, int num2)
{
    // Do something with two integer parameters in a specific order
}

void Calculate(int num2, int num1)
{
    // Do something with the same integer parameters in a different order
}

Option D) All of these - This option is correct. All of the mentioned options are valid ways to overload a method in C#. By combining different parameter data types, different numbers of parameters, and different orders of parameters, we can achieve method overloading.

The correct answer is D) All of these. This option is correct because all the mentioned ways are valid ways to overload a method in C#.

Which of the following is incorrect about System.Text.StringBuilder and System.String?

  1. StringBuilder is more efficient when there is a large amount of string manipulation

  2. Strings are immutable, so each time a string is changed, a new instance in memory is created.

  3. StringBuilder is mutable; when you modify an instance of the StringBuilder class, you modify the actual string, not a copy

  4. Strings are mutable in .Net


Correct Option: D

AI Explanation

To answer this question, you need to understand the differences between System.Text.StringBuilder and System.String in terms of mutability and efficiency.

Option A) StringBuilder is more efficient when there is a large amount of string manipulation - This option is correct. StringBuilder is designed to be more efficient when there is a need for frequent string manipulation. It provides methods to modify the string without creating a new instance in memory each time.

Option B) Strings are immutable, so each time a string is changed, a new instance in memory is created - This option is correct. System.String objects are immutable, meaning they cannot be changed once created. When you modify a string, a new instance is created in memory.

Option C) StringBuilder is mutable; when you modify an instance of the StringBuilder class, you modify the actual string, not a copy - This option is correct. StringBuilder objects are mutable, meaning they can be modified without creating a new instance. When you modify a StringBuilder object, you modify the actual string it holds.

Option D) Strings are mutable in .Net - This option is incorrect. Strings are immutable in .NET. Once a string is created, it cannot be changed. Any modifications to a string result in the creation of a new string instance in memory.

The correct answer is D) Strings are mutable in .Net. This option is incorrect because strings are actually immutable in .NET.

  1. It is available to classes that are within the same assembly and derived from the specified base class.

  2. It is available within the class definition

  3. It is the most permissive access level

  4. It is the least permissive access level


Correct Option: A
- Hide questions