OOPS Interview Questions and Answers (133) - Page 6

Can an Abstract class have a constructor?

Yes,an Abstract Class can have a constructor.In general,a class constructor is used to initialize fields or variables.An abstract class constructor is used to initialize fields of the abstract class.We would provide a constructor for an abstract class if we want to initialize certain fields of the abstract class before the instantiation of a child-class takes place. An abstract class constructor can also be used to execute code that is relevant for every child class.This prevents duplicate code.
We cannot create an instance of an abstract class.So,what is the use of a constructor in an abstract class?

Though we cannot create an instance of an abstract class,we can create instances of the classes that are derived from the abstract class.So,when an instance of derived class is created,the parent abstract class constructor is automatically called.

Note: Abstract classes can not be directly instantiated.The abstract class constructor gets executed through a derived class.So,it is a good practice to use protected access modifier with abstract class constructor.Using public does not make sense.
Which of the class we can inherit?

NOTE: This is objective type question, Please click question title for correct answer.
Which class prevents inheritance?

NOTE: This is objective type question, Please click question title for correct answer.
Which way is used to convert Value-Type to Reference-Type?

NOTE: This is objective type question, Please click question title for correct answer.
Which way is used to convert Reference-Type to Value-Type?

NOTE: This is objective type question, Please click question title for correct answer.
Which of the following statement(s) is true concerning Static Classes?

NOTE: This is objective type question, Please click question title for correct answer.
What is the equivalent of static class in VB.Net?

NOTE: This is objective type question, Please click question title for correct answer.
Which statement is true about Sealed Classes?

NOTE: This is objective type question, Please click question title for correct answer.
What is the syntax of Sealed Class in C#?

Sealed class is declared with Sealed keyword.
Syntax:-
sealed class credit

{
public int Add(int a,int b)
{
return a + b;
}
}

As sealed class do not need to be derived means if we declare any class as Sealed class,then no body can enforce to inherit.If we take an example of Credit card,then it's information need not be shared by any one.So we can make such class as sealed.
What is the equivalent of Sealed Class in VB.Net?

NotInheritable keyword is an equivalent of Sealed Class .
For Ex:-
Public NotInheritable Class Credit

Private Sub New()
'Constructor Initialization
End Sub
End Class


For Example:-
NotInheritable Class S1 

'do your code
End Class

Class S2
Inherits S1

When derive a class from S1 then will get below error:-
S2 cannot onherit from class 'S1' because 'S1' is declared 'NotInheritable'

What do we mean by partial class in OOP?

A partial class is a Class and is defined in 2 or more classes that are split the file into multiple files.And developers can use these files to work separately and later it is compiled to make a single to.

For Example:-
public partial class Employee

{
}

Which statement is correct about Partial Classes?

NOTE: This is objective type question, Please click question title for correct answer.
What are the advantages of partial classes?

Following are the advantages of Partial classes:-
1). We can separate User Interface part code and business logic code so that it is easy to read and understand by anybody.
2). More than one developers can work at a time.
3). As Partial classes can be separated then it can again be reunited of compilation.
How can we identify Partial Class in C#?

When we create any application in Dot Net and add any new web form then 2 files are generated which is named as aspx.cs/aspx.vb and aspx.designer.cs/vb.These two files have the same class with the partial keyword .The .aspx.cs/vb class is used for writing business logic code where aspx.designer.cs/vb file is used for having asp.net controls.
Which statement is/are correct about Interface?

NOTE: This is objective type question, Please click question title for correct answer.
Which statement is correct about Abstract classes?

NOTE: This is objective type question, Please click question title for correct answer.
Which statement is correct about Method Overloading?

NOTE: This is objective type question, Please click question title for correct answer.
Which statement is correct about Method Overriding?

NOTE: This is objective type question, Please click question title for correct answer.
What are the rules about Function Overloading?

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories