+ 1
Can anyone please explain the oops concepts in java with example.
2 Antworten
+ 4
* Consider an example of animals
* So class is Animals
* Cat , dog, etc are instances of Animals class and they r called objects
* Properties or behaviours of the Animals class are name, height ,color, etc
* And methods r the actions done by the animals like eating, walking, etc.
* And these methods can be called to any of it objects (cat,dog,etc ).
+ 2
When you create a class they should use the Single Responsibility Principle so they should only handle one thing e.g the Animal class. You also have encapsulation which is a method of hiding variable and methods using the 'private' keyword so they cannot be modified outside the class. Another term you may hear is polymorphism which allows a single interface but many implementations using method overloading and overriding.