Monday, July 14, 2014

Java OO Conceptions

What is Composition  and Inheritance
Composition:  create objects of your existing class inside the new class.
Inheritance: create a new class as a type of an existing class.
Classes is allowed to inherit commonly used state and behavior from other classes.

What is Polymorphism(dynamic binding)
The ability of an object to take on many forms(You have the same interface from the base class, and different forms using that interface: the different versions of the dynamically bound methods. ).
Like override( when a parent class reference is used to refer to a child class object.).

Data Abstract
Abstract Method: a method that is incomplete; it has only a declaration and no method body;
abstract void f();
An abstract class 可以没有abstract method, 但是有abstract method的class一定是abstract class。
You can not make an object of an abstract class!!!

Abstract Class:
  • The implementation is provided by inheritors. 
  • Abstract class can have fields. 
  • Can have complete default code / details to be overridden. 
  • Can have access modifiers. 
  • Is-a relationship
Interface:
  • Support multiple inheritance. 
  • Interface can also have fields, but these are implicitly static and final. 
  • Completely abstract class, can not have code, just signature. 
  • Can not have Access Modfiers, everything is assumed as public. 
  • Has-a realtionship.
Encapsulation(data hiding):
Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods.

No comments:

Post a Comment