.NET,ASP.NET,C#.NET Interview Questions and Answers
Question.1 Can you prevent a class from overriding?
Answer: Yes, you can prevent a class from overriding.
In C#:
You can prevent a class from overriding by using the sealed keyword.
In Visual Basic: is You can prevent a class from overriding by using the Not inheritable keyword.
Question.2 What is the syntax to inherit from a class in C#?
Answer: When a class is derived from another class, then the members of the base class become the members of the derived class. The access modifiers used while accessing members of the base class specifies the access status of the base class members inside the derived class.[sociallocker]
Question.3 Can you allow a class to be Inherited. But prevent e method front being overridden in C#?
Answer: Yes, just declare the clan public and flake the method sealed.
Question.4 What does the keyword virtual declare for a method or property?
Answer: The virtual keyword is used to modify a method, property, indexer, or event declaration and allow it to be overridden in a derived doss.
Question.5 How is method overriding different from method overloading?
Answer: In method overloading —the signature of a method consists of the method name and a parameter lest, which consists of the order and the type of method arguments. Overloading a method simply involves another method with the same name within the class.
In method overriding —Overriding occurs only with respect to in heritance and occurs when a child has a method with the same signature as a parents. Method. When overriding a method, you can change the behavior of the method for the derived class.
Question.6 Can you declare an overridden method to be static lithe original method is not static?
Answer: No. The signature of the virtual method neat remains the same.
Question.7 What are the different ways a method can be overloaded?
Answer: A Method can be overloaded:
By varying the numbers of parameters,
By using different data types for the Parameters.
By using different eminence al the Parameters.
Question.8 What is the function of the Try-Catch-Finally block?
Answer: The try block encloses that statement; that can case exception and the catch block handles the exception if it occurs. The finally block always executes, whether an exception has occurred or not. The finally block is genera used to perform arty cleanup process. If any exception occurs in the try blocks, the program control directly transfers to Its corresponding catch block and later to the finally block. If no exception occurs Inside the try block, then the program Control transfers directly to the finally block.
Question.9 Is using of exceptions in C# recommended?
Answer: Yes, exceptions are the recommended error-handling mechanism in .NET Framework.
Question.10 Can. meets define their own exceptions in code?
Answer: Yes, Customized exceptions can be defined n code by deriving from the System Exception Cass.
Question.11 When is an exception thrown?
Answer: The exception handling feature in NET Frame work helps you to deal with any unexpected situations that occur when a program is running, for example, dividing a number by zero or passing a string value to a variable that holds an integer value. In such a situation, you need to capture and handle errors.
Question.12 Do we use the throws clause to raise an exception?
Answer: No, the throws clause is not used to raise an exception. The throw statement signals the occurrence of an exception during the execution of a program. When the program encounters a throw statement, the method terminates and returns the error to the calling method.
Question.13 If an array has 11 elements, then what is the Index of the last element?
Answer: The index of the last element is 10.
Question.14 Can a class simultaneously inherit from two other classes?
Answer: A class and not Inherit from more than one class.
Question.15 How do we auto size a button to fit its text?
Answer: The button control has the autosize property, which can be set to true of false. If we set the value of the auto size property to true, then the Button control automatically alters its size according to the content displayed on it.
Question.16 Explain the method adopted to customize the visual appearance of a button control in C#?
Answer: The Button class defines the functionalities or the Button control in .NET Framework. We can create a new class that extends from the Button class, as we have created the MyButton class in the code given below. In this class, we declare an object of the PaintEventHandler class. Further, we add a custom Paint event handler method that performs custom drawing.
Question.17 How can we display an icon or a bitmap image on a button control?
Answer: The Button class contains the imago property, which is used to set an image on the button control. Also, we can set the alignment of the image by using the Impaneling property of the Button class.
Question.18 A Windows Form will not show the Minimize, Maximize, and Close buttons, lithe Controlfrox property of the form Is set to False. (True/False)
Answer: True
Question.19 How is anchoring different from docking?
Answer: Docking refers to attaching a control to either an edge (top, right, bottom, or left) or the client area of the parent control. On the other hand in anchoring you specify the distance that each edge of your control maintains from the edges of the parent control.[/sociallocker]
Learn ASP NET Online Course