hare singh nayak
hi friends
i have faced three interview and oops concepts are asked there with the real life example and implement in coding. i told them all concept theoretically but could not implemented practically and because of that i was not selected . so please explain me oops concept with practical example. so it would be more helpful for me and other crazyengeers.
thank you in advance
As iAnoop said, it is better if u can give question which were asked and what u answer, so that a healthy discussion can be carried out on it.
But still, I will give u an example:
Suppose in real life I take a ball as an object (classical example 😉 ).
In real life ball has
attributes (size, weight, color etc.) and
behaviour (bounces, squeezes etc. ).
Similarly in programming u can implement it by:
- Creating a class ball which creates objects of ball type
- Creating instance variables in class as size, weight etc. to represent attributes (or u may call it as state).
- Creating functions (or methods 😁 ) eg. bounces , squeezes etc. to represent it's behaviour.
- And different types of constructors ( as per need 😛 )
As class is ready, simply create objects of ball class and call functions as per need, and u have a practical example of OOPS concepts,
NOTE: Do keep in mind to mention other Oops concepts which are to be implemented, eg. How encapsulation and abstraction are working in this example(more on this later),
but first tell what questions u actually faced and how u faced those ☕