Skip to main content

Stage 4 - Classes and OOP

Q18. What is a class?

Quick interview answer: A class is a blueprint for creating objects. For example, a Student class can define properties like Name and Marks, and methods like CalculateResult.

Study in detail: Classes - This article expands the topic with complete explanation, examples, and practice code.

Q19. What is an object?

Quick interview answer: An object is a real instance created from a class. If Student is the blueprint, then new Student() creates an actual student object in memory.

Study in detail: Classes - This article expands the topic with complete explanation, examples, and practice code.

Q20. What is a constructor?

Quick interview answer: A constructor runs automatically when an object is created. It is mainly used to give required starting values to the object, such as student name or admission number.

Study in detail: Classes - This article expands the topic with complete explanation, examples, and practice code.

Q21. What is the difference between field and property?

Quick interview answer: A field stores data directly inside a class. A property provides controlled access to that data. In real applications, properties are preferred because they support validation, binding, and framework features.

Study in detail: Properties - This article expands the topic with complete explanation, examples, and practice code.

Q22. What is encapsulation?

Quick interview answer: Encapsulation means hiding internal data and exposing only safe ways to use it. For example, fields can be private, and public properties or methods can control how values are changed.

Study in detail: Encapsulation - This article expands the topic with complete explanation, examples, and practice code.

Q23. What are access modifiers?

Quick interview answer: Access modifiers decide where a class member can be used. public means accessible anywhere, private means only inside the same class, protected means class and child classes, and internal means inside the same project or assembly.

Study in detail: Encapsulation - This article expands the topic with complete explanation, examples, and practice code.

Q24. What is inheritance?

Quick interview answer: Inheritance means one class can reuse members from another class. For example, Student and Teacher can inherit common properties like Name from a Person class.

Study in detail: Inheritance - This article expands the topic with complete explanation, examples, and practice code.

Q25. What is polymorphism?

Quick interview answer: Polymorphism means the same method call can behave differently depending on the actual object. In C#, this is commonly done using virtual in the base class and override in the child class.

Study in detail: Inheritance - This article expands the topic with complete explanation, examples, and practice code.

Q26. What is the difference between override and new?

Quick interview answer: override changes a base class method in the correct polymorphic way. new hides the base method, so the method that runs may depend on the reference type. In most real projects, override is preferred.

Study in detail: Method hiding - new vs override - This article expands the topic with complete explanation, examples, and practice code.

Q27. What is the difference between overloading and overriding?

Quick interview answer: Overloading means same method name with different parameters in the same class. Overriding means a child class changes the behavior of a virtual method from the parent class.

Study in detail: Override vs Overload - This article expands the topic with complete explanation, examples, and practice code.

Q28. What is an abstract class?

Quick interview answer: An abstract class cannot be created directly with new. It is used as a base class when child classes must share common behavior but also provide their own implementation.

Study in detail: Abstract classes - This article expands the topic with complete explanation, examples, and practice code.

Q29. What is an interface?

Quick interview answer: An interface is a contract that says what a class must do. It helps us write flexible code because different classes can implement the same interface in different ways.

Study in detail: Interfaces - This article expands the topic with complete explanation, examples, and practice code.

Q30. What is the difference between abstract class and interface?

Quick interview answer: Use an abstract class when related classes share common base behavior. Use an interface when different classes must follow the same contract, even if they are not closely related.

Study in detail: Abstract classes and Interfaces - This article expands the topic with complete explanation, examples, and practice code.

Q31. What is a struct?

Quick interview answer: A struct is a value type and is copied when assigned. It is best for small simple values. For business objects like Student, Teacher, and Exam, a class is usually better.

Study in detail: Structs - This article expands the topic with complete explanation, examples, and practice code.

nexcoding.in