Difference between revisions of "Object Oriented programming"

From Conservapedia
Jump to: navigation, search
(Undo revision 796599 by Fionat (Talk))
(Polymorphism)
Line 9: Line 9:
 
Polymorphism allows an object to appear as another object. This means that a complex object can appear to be a simple one. The example below shows that you can have a specific model of car, such as the [[Model T]], which looks like and acts like a normal car.
 
Polymorphism allows an object to appear as another object. This means that a complex object can appear to be a simple one. The example below shows that you can have a specific model of car, such as the [[Model T]], which looks like and acts like a normal car.
  
=== Example ===
+
=== Example (Java)===
  
 
<pre>
 
<pre>

Revision as of 21:36, July 14, 2011

Object Oriented programming (OOP) languages are based around the paradigm of objects that interact with each other to produce functionality. There are many programming languages that are designed around object oriented principles, such as Java.

Objects

Objects are components of an object oriented language, consisting of properties and methods.

An object is also known as a Type or Class.

Polymorphism

Polymorphism allows an object to appear as another object. This means that a complex object can appear to be a simple one. The example below shows that you can have a specific model of car, such as the Model T, which looks like and acts like a normal car.

Example (Java)

public class ModelT extends Car {
    private Color color = Color.BLACK;
    private String model = "T";

    public void setColor(Color color){
        this.color = color;
    }

    public Color getColor(){
        return this.color;
    }

    public String getModel(){
        return model;
    }
}

public abstract class Car {
    void setColor(Color color);
    Color getColor();
    String getModel();
}