Tag: class


The 3 Main Principles of Object Oriented Programming - How to Program With Java

The 3 Main Principles of Object Oriented Programming – How to Program With Java

 Object-Oriented Programming Object-Oriented Programming (or OOP) is actually classified by three main principles. 1) Encapsulation 2) Inheritance 3) Polymorphism Encapsulation: These appear to be frightening terms but are actually fairly easy principles to assist. In order to figure out how to program with java, you’ll need to understand these principles. So let’s consider our first main concept of OOP, encapsulation. Encapsulation just means we want to limit the access that some other pieces of code have to this particular object. So, to illustrate, if you have a Person object, and this Person object has a first and last name as attributes. In the event another chunk of code attempts to modify your person object’s first name to say “Frank3″, you could take a note of what the first name is trying to be set to, and remove any digits so that we are simply left with ” Frank. ” Without encapsulation, we will not have the ability to prevent “silly programmers” from modifying the values of our variables to something which would not seem sensible, or worse, break the application. Seem sensible? Inheritance: The second concept of OOP and an essential principle if you wish to learn how to program with Java is Inheritance. This specific concept refers to a superclass (or parent class) and a sub-class (or child class) and the simple fact that a child class acquires each of the attributes of its parent. You can think of it in terms of a real-world circumstance, like a real parent and child. A child will probably inherit certain hits from his or her parents, like say, eye color or hair color. Allow us to imagine yet another example in terms of programming, say we have superclass “Vehicle” and sub-classes “Car” and “Motorcycle”. A “Vehicle” possesses tires, there through inheritance…

Continue Reading