• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

polymorphism and encapsulation

 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to have simple and perfect definition with example for polymorphism and encapsulation so I will understand easily?
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Polymorphism---> "many forms" i.e it can be called using many names.

now th method eat() can be called by using the reference of either Animal or Dog or Cat i.e by many names..

Encapsulation---> Wrapping up of all data into methods such that they are not visible to outside world but are accessible only through those methods in which they are wrapped up. For this you should mark all your variables whether static or instance private



So here anyone who wants to set a name for Animal have to go through public method setName() without knowing what is happening in the method and without accessing directly the instance variable name..

I hope you got it..
 
Lookout! Runaway whale! Hide behind this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic