21⟩ What is Object?
Object is anything that is identifiable as a single material item.
“Object-oriented programming (OOP) is a programming paradigm, In this OOP Interview Questions and Answers you will learn that OOP uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as information hiding, data abstraction, encapsulation, modularity, polymorphism, and inheritance. Learn OOP by OOP Interview Questions and Answers”
Object is anything that is identifiable as a single material item.
Method overriding is a feature that allows to invoke functions (that have the same signatures) and that belong to different classes in the same hierarchy of inheritance using the base class reference. In C# it is done using keywords virtual and overrides .
To indicate that a field should only be stored once no matter how many instance of the class we create.
No. If you try to create a private class in a Namespace, Compiler will throw a compile time error “Namespace elements cannot be explicitly declared as private, protected, or protected internal”.
Reason: The message says it all. Classes can only be declared as private, protected or protected internal when declared as nested classes, other than that, it doesn't make sense to declare a class with a visibility that makes it unusable, even in the same module. Top level classes cannot be private, they are "internal" by default, and you can just make them public to make them visible from outside your DLL.
When you declare a Constructor with Private access modifier then it is called Private Constructor. We can use the private constructor in singleton pattern.
If you declare a Constructor as private then it doesn’t allow to create object for its derived class, i.e you loose inherent facility for that class.
Example:
Class A
{
// some code
Private Void A()
{
//Private Constructor
}
}
Class B:A
{
//code
}
B obj = new B();// will give Compilation Error
Because Class A constructor declared as private hence its accessibility limit is to that class only, Class B can't access. When we create an object for Class B that constructor will call constructor A but class B have no rights to access the Class A constructor hence we will get compilation error.
This keyword indicates that a member can be overridden in a child class. It can be applied to methods, properties, indexes and events.
Use the override modifier to modify a method, a property, an indexer, or an event. An override method provides a new implementation of a member inherited from a base class. The method overridden by an override declaration is known as the overridden base method. The overridden base method must have the same signature as the override method.
You cannot override a non-virtual or static method. The overridden base method must be virtual, abstract, or override.
It provides a convenient way to reuse existing fully tested code in different context thereby saving lot of coding.
Inheritance of classes in C# is always implementation Inheritance.
No, Struct can't be inherited as this is implicitly sealed.
Yep. But ..
► Its possible If its a static method.
► Its possible by inheriting from that class also.
► Its possible from derived classes using base keyword.
It is possible to declare a method as Static provided that they don't attempt to access any instance data or other instance methods.
An interface is a contract & defines the requisite behavior of generalization of types.
An interface mandates a set of behavior, but not the implementation. Interface must be inherited. We can't create an instance of an interface.
An interface is an array of related function that must be implemented in derived type. Members of an interface are implicitly public & abstract.
An interface can inherit from another interface.
The new modifiers hides a member of the base class. C# supports only hide by signature.
A Class is the generic definition of what an object is a template.
The keyword class in C# indicates that we are going to define a new class (type of object)
An Attribute is a declarative tag which can be used to provide information to the compiler about the behaviour of the C# elements such as classes and assemblies.
C# provides convenient technique that will handle tasks such as performing compile time operations , changing the behaviour of a method at runtime or maybe even handle unmanaged code.
C# Provides many Built-in Attributes
Some Popular ones are
- Obsolete
- DllImport
- Conditional
- WebMethod
and Many more.
Members please keep on posting more responses providing more In-Built attributes.
Regards Hefin Dsouza
Use the new modifier to explicitly hide a member inherited from a base class. To hide an inherited member, declare it in the derived class using the same name, and modify it with the new modifier.
Well, Declare a class with public access specifier and mark all it's method to sealed . As anything which is declared with sealed keyword cannot be inherited.