What is the output of the following code in Test class Class Myclass Dim Num as Integer Private Sub New (i as integer) Num=I End sub End class Class Test Sub Main() Dim c as Myclass C=New Myclass (10) End sub End Class Num variable of Myclass is initialized to 10

  1. Run Time Error

  2. Compiler Error

  3. StackOverflow Exception

  4. NONE


Correct Option: B

AI Explanation

To answer this question, let's analyze the code step by step:

First, we have the definition of the Myclass class. This class has one member variable Num of type Integer and a constructor New that takes an Integer parameter i and assigns its value to the Num variable.

Next, we have the Test class, which contains the Main method. In the Main method, an instance of the Myclass class is created and assigned to the variable c. The constructor New is called with the argument 10.

Now, let's go through each option to understand why it is correct or incorrect:

Option A) Run Time Error - This option is incorrect. There are no runtime errors in the given code. The code will execute without any exceptions.

Option B) Compiler Error - This option is correct. The code will not compile due to a compiler error. The issue is with the line C=New Myclass (10). In VB.NET, the New keyword is not used to create instances of classes. Instead, you can directly call the constructor like C = Myclass(10). The correct syntax for creating an instance of the Myclass class and assigning it to the variable c would be c = New Myclass(10).

Option C) StackOverflow Exception - This option is incorrect. There is no recursive or infinite looping code in the given code, so a StackOverflowException will not occur.

Option D) NONE - This option is incorrect. As explained above, the correct answer is Option B.

The correct answer is B) Compiler Error. This option is correct because the code will not compile due to a syntax error in the line C=New Myclass (10).

Find more quizzes: