Can anyone please explain the oops concepts in java with example. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone please explain the oops concepts in java with example.

12th Feb 2017, 10:04 AM
Arun Yadav
Arun Yadav - avatar
2 Answers
+ 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 ).
12th Feb 2017, 12:37 PM
rossi
rossi - avatar
+ 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.
12th Feb 2017, 3:29 PM
Mike Allen
Mike Allen - avatar