10000 GitHub - hershudmehtus/oop-interview-questions: 🟣 OOP Interview Questions Answered to help you get ready for your next developer interview.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

hershudmehtus/oop-interview-questions

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 

Repository files navigation

πŸ–² Essential 54 OOP (Object Oriented Programming) interview questions and answers in 2021

OOP is the most popular programming paradigm used in the tech industry. Follow along and check our list of 54 basic and advanced OOP interview questions and answers for experienced developers and get ready for your next tech interview in 2021.



You can also find all 54 answers here πŸ‘‰πŸΌ https://devinterview.io/dev/oop-interview-questions


πŸ”Ή 1. What is object-oriented programming (OOP)?

Answer:

OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object is created in the program to represent a class. Therefore, an object encapsulates all the features, such as data and behavior that are associated to a class. OOP allows developers to develop modular programs and assemble them as software. Objects are used to access data and behaviors of different software modules, such as classes, namespaces, and sharable assemblies. .NET Framework supports only OOP languages, such as Visual Basic .NET, Visual C#, and Visual C++.

Source:Β indiabix.comΒ  Β 


πŸ”Ή 2. What is inheritance?

Answer:

Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and speeds up implementation time.

When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.

The idea of inheritance implements the IS-A relationship. For example, mammal IS A animal, dog IS-A mammal hence dog IS-A animal as well, and so on.

Source:Β tutorialspoint.comΒ  Β 


πŸ”Ή 3. Can you inherit private members of a class?

Answer:

No, you cannot inherit private members of a class because private members are accessible only to that class and not outside that class.

Source:Β indiabix.comΒ  Β 


πŸ”Ή 4. What is polymorphism?

Answer:

The word polymorphism means having many forms. In object-oriented programming paradigm, polymorphism is often expressed as one interface, multiple functions.

Source:Β tutorialspoint.comΒ  Β 


πŸ”Ή 5. What is encapsulation?

Answer:

Encapsulation is defined as the process of enclosing one or more items within a physical or logical package. Encapsulation, in object oriented programming methodology, prevents access to implementation details.

Source:Β tutorialspoint.comΒ  Β 


πŸ”Ή 6. Why is the virtual keyword used in code?

Answer:

The virtual keyword is used while defining a class to specify that the methods and the properties of that class can be overridden in derived classes.

Source:Β indiabix.comΒ  Β 


πŸ”Ή 7. Explain the concept of constructor?

Answer:

Constructor is a special method of a class, which is called automatically when the instance of a class is created. It is created with the same name as the class and initializes all class members, whenever you access the class. The main features of a constructor are as follows:

  • Constructors do not have any return type.
  • Constructors can be overloaded.
  • It is not mandatory to declare a constructor; it is invoked automatically by .NET Framework.
Source:Β indiabix.comΒ  Β 


πŸ”Ή 8. What is the difference between procedural and object-oriented programming?

Answer:

Procedural programming is based upon the modular approach in which the larger programs are broken into procedures. Each procedure is a set of instructions that are executed one after another. On the other hand, OOP is based upon objects. An object consists of various elements, such as methods and variables.

Access modifiers are not used in procedural programming, which implies that the entire data can be accessed freely anywhere in the program. In OOP, you can specify the scope of a particular data by using access modifiers - public, private, internal, protected, and protected internal.

Source:Β indiabix.comΒ  Β 


πŸ”Ή 9. What is the difference between a class and a structure?

Answer:

Class:

  • A class is a reference type.
  • While instantiating a class, CLR allocates memory for its instance in heap.
  • Classes support inheritance.
  • Variables of a class can be assigned as null.
  • Class can contain constructor/destructor.

Structure:

  • A structure is a value type.
  • In structure, memory is allocated on stack.
  • Structures do not support inheritance.
  • Structure members cannot have null values.
  • Structure does not require constructor/destructor and members can be initialiazed automatically.
Source:Β indiabix.comΒ  Β 


πŸ”Ή 10. What is an object?

Answer:

Objeects are instance of classes. It is a basic unit of a system. An object is an entity that has 8000 attributes, behavior, and identity. Attributes and behavior of an object are defined by the class definition.

Source:Β indiabix.comΒ  Β 


πŸ”Ή 11. What is a class?

Answer:

A class describes all the attributes of objects, as well as the methods that implement the behavior of member objects. It is a comprehensive data type, which represents a blue print of objects. It is a template of object.

A class can be defined as the primary building block of OOP. It also serves as a template that describes the properties, state, and behaviors common to a particular group of objects.

A class contains data and behavior of an entity. For example, the aircraft class can contain data, such as model number, category, and color and behavior, such as duration of flight, speed, and number of passengers. A class inherits the data members and behaviors of other classes by extending from them.

Source:Β indiabix.comΒ  Β 


πŸ”Ή 12. What is the relationship between a class and an object?

Answer:

A class acts as a blue-print that defines the properties, states, and behaviors that are common to a number of objects. An object is an instance of the class. For example, you have a class called Vehicle and Car is the object of that class. You can create any number of objects for the class named Vehicle, such as Van, Truck, and Auto.

The new operator is used to create an object of a class. When an object of a class is instantiated, the system allocates memory for every data member that is present in the class.

Source:Β indiabix.comΒ  Β 


πŸ”Ή 13. Explain the basic features of OOPs

Answer:

The following are the four basic features of OOP:

  • Abstraction - Refers to the process of exposing only the relevant and essential data to the users without showing unnecessary information.
  • Polymorphism - Allows you to use an entity in multiple forms.
  • Encapsulation - Prevents the data from unwanted access by binding of code and data in a single unit called object.
  • Inheritance - Promotes the reusability of code and eliminates the use of redundant code. It is the property through which a child class obtains all the features defined in its parent class. When a class inherits the common properties of another class, the class inheriting the properties is called a derived class and the class that allows inheritance of its common properties is called a base class.
Source:Β indiabix.comΒ  Β 


πŸ”Ή 14. A structure in C# can implement one or more interfaces. Is it true or false?

Answer:

Yes, it is true. Like classes, in C#, structures can implement one or more interfaces.

Source:Β indiabix.comΒ  Β 


πŸ”Ή 15. What is polymorphism, what is it for, and how is it used?

Answer:

Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface.

The beauty of polymorphism is that the code working with the different classes does not need to know which class it is using since they’re all used the same way. A real world analogy for polymorphism is a button. Everyone knows how to use a button: you simply apply pressure to it. What a button β€œdoes,” however, depends on what it is connected to and the context in which it is used β€” but the result does not affect how it is used. If your boss tells you to press a button, you already have all the information needed to perform the task.

Source:Β stackoverflow.comΒ  Β 


πŸ”Ή 16. How can you prevent a class from overriding in C#?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 17. When should I use a struct instead of a class?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 18. What are abstract classes? What are the distinct characteristics of an abstract class?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 19. How can you prevent your class to be inherited further?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 20. What are the different ways a method can be overloaded?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 21. Is it possible for a class to inherit the constructor of its base class?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 22. How is method overriding different from method overloading?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 23. State the features of an interface.

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 24. How could you defineAbstraction in OOP?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 25. Can you specify the accessibility modifier for methods inside the interface?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 26. Can you allow a class to be inherited, but prevent a method from being overridden in C#?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 27. What do you mean by data encapsulation?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 28. What are similarities between a class and a structure?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 29. Interface or an Abstract Class: which one to use?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 30. Explain the concept of destructor?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 31. What is Coupling in OOP?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 32. What exactly is the difference between an interface and abstract class?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 33. Explain different types of inheritance.

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 34. Differentiate between an abstract class and an interface.

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 35. When should I use an interface and when should I use a base class?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 36. What is the difference between an abstract function and a virtual function?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 37. What is the difference between cohesion and coupling?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 38. Does .NET support multiple inheritance?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 39. Can you declare an overridden method to be static if the original method is not static?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 40. What is a static constructor?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 41. What is Cohesion in OOP?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 42. What's the advantage of using getters and setters - that only get and set - instead of simply using public fields for those variables?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 43. Can you declare a private class in a namespace?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 44. In terms that an OOP programmer would understand (without any functional programming background), what is a monad?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 45. What is the difference between association, aggregation and composition?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 46. Can you provide a simple explanation of methods vs. functions in OOP context?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 47. You have defined a destructor in a class that you have developed by using the C# programming language, but the destructor never executed. Why did the destructor not execute?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 48. What is LSP (Liskov Substitution Principle) and what are some examples of its use (good and bad)?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 49. Could you elaborate Polymorphism vs Overriding vs Overloading?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 50. What does it mean to β€œprogram to an interface”?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 51. Why Doesn't C# Allow Static Methods to Implement an Interface?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 52. What is the difference between a mixin and inheritance?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 53. Why prefer composition over inheritance? What trade-offs are there for each approach? When should you choose inheritance over composition?

πŸ‘‰πŸΌ Check all 54 answers


πŸ”Ή 54. How do I test a pri 4FD3 vate function or a class that has private methods, fields or inner classes?

πŸ‘‰πŸΌ Check all 54 answers


About

🟣 OOP Interview Questions Answered to help you get ready for your next developer interview.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0