Friday, April 12, 2013

Java – OOP intro


Some concepts in Object-Oriented Programming.
Object: Repository of data, such as milk or jam. 
Class: Type of object. 
Method: Procedure or Function that operates on an object (or class).
Inheritance: A class can inherit properties from a more general class. For instance, Shopping List inherits from List class the property of storing a sequence of items.
Polymorphism: One method call works on several classes, even if the classes need different implementation. e.g. “addItem” method on every kind of List, even though adding item to ShoppingList is different from ShoppingCart.
Polymorphism is the thing that distincts from other languages.
Object-oriented: Each object knows its own class&method. Each ShoppingList & ShoppingCart knows which addItem method it uses.


Code example:

String myString;
// mystring is a variable
myString = new String();
// new String() is called a constructor. It creates a string object,
// "=" causes myString to a reference the object

Differences between Java & Scheme:

  1. Everything in Java has a type; you must declare it.
  2. Scheme program (.sch) --> (eval) Answer. Java program (.java) --> (javac) .class Files --> (java) Answer

No comments:

Post a Comment