Q) What is Polymorphism?
A) It means one interface and many forms. Polymorphism is a characteristics of being able to assign a different meaning or usage to something in different contexts specifically to allow an entity such as variables, functions or an object to have more than one form.
There are 2 Types of Polymorphism:
Compile Time : Function and Operator overloading.
Runtime : Inheritance and Virtual functions.
Q) Can struct be inherited ?
A) No, as it is implicitly sealed.
Q) What is Static field ?
A) Its a field which can only be stored once no matter how many instance of the class is created.
Q) What is static Method?
A) it is possible to declare a method as static provided that they don't attempt to access any instance data or other instance method.
Q) What is New modifiers ?
A) The New modifiers hides a member of the base class.
Q) What is sealed modifiers ?
A) Sealed types cannot be inherited and are concrete. Sealed modifiers can also be applied to instance methods, properties, events and indexes. It can't be applied to static members. Sealed members are allowed in sealed and non-sealed classes.
Q) What is Interface ?
A) An Interface is a contract and defines the requisite behavior of generalization of types. An interface mandates a set of behavior, but not the implementation. interface must be inherited. we cannot create an instance of an interface.
An interface is an array of related functions that must be implemented in derived type. Members of an interface are implicitly public and abstract.
An interface can inherit from another interface.
Q) When to use Interface over Abstract Class ?
A) Abstract Classes : Classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying ClassAbstract obj = new ClassAbstract();
Abstract classes contains one or more abstract methods, i.e. method body only no implementation.
Interface : These are same as abstract classes only difference is we can only define method defination and no implementation.
When to use wont depends on various reasons. One being design choice.
One reason for using abstract classes is we can code common functionality and force our developer to use it. i can have a complete class but i can still mark the class as abstract. Developing by interface helps in object based communication.
A) It means one interface and many forms. Polymorphism is a characteristics of being able to assign a different meaning or usage to something in different contexts specifically to allow an entity such as variables, functions or an object to have more than one form.
There are 2 Types of Polymorphism:
Compile Time : Function and Operator overloading.
Runtime : Inheritance and Virtual functions.
Q) Can struct be inherited ?
A) No, as it is implicitly sealed.
Q) What is Static field ?
A) Its a field which can only be stored once no matter how many instance of the class is created.
Q) What is static Method?
A) it is possible to declare a method as static provided that they don't attempt to access any instance data or other instance method.
Q) What is New modifiers ?
A) The New modifiers hides a member of the base class.
Q) What is sealed modifiers ?
A) Sealed types cannot be inherited and are concrete. Sealed modifiers can also be applied to instance methods, properties, events and indexes. It can't be applied to static members. Sealed members are allowed in sealed and non-sealed classes.
Q) What is Interface ?
A) An Interface is a contract and defines the requisite behavior of generalization of types. An interface mandates a set of behavior, but not the implementation. interface must be inherited. we cannot create an instance of an interface.
An interface is an array of related functions that must be implemented in derived type. Members of an interface are implicitly public and abstract.
An interface can inherit from another interface.
Q) When to use Interface over Abstract Class ?
A) Abstract Classes : Classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying ClassAbstract obj = new ClassAbstract();
Abstract classes contains one or more abstract methods, i.e. method body only no implementation.
Interface : These are same as abstract classes only difference is we can only define method defination and no implementation.
When to use wont depends on various reasons. One being design choice.
One reason for using abstract classes is we can code common functionality and force our developer to use it. i can have a complete class but i can still mark the class as abstract. Developing by interface helps in object based communication.
0 comments:
Post a Comment