AdSense

Saturday, December 13, 2014

From Queue to other basic concepts (Interface and Inheritance)

java.util.Queue is a subtype of java.util.Collection interface. A queue is designed to have elements inserted at the end of the queue, and elements removed from the beginning of the queue. 

Queue is an interface, we need to instantiate a concrete implementation of the interface in order to use it. In Java Collections API, we can use:

java.util.LinkedList
java.util.PriorityQueue : stores its elements internally according to their natural order (if they implement Comparable), or according to a Comparator passed to the PriorityQueue. 



Interface:
Objects define their interaction with the outside world through the methods that they expose. Methods form the object's interface with the outside world. 
An interface is a group of related methods with empty bodies. Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contact between the class and the outside world, and this contract is enforced at build time by the compiler. If a class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile. 

class ACMEBicycle implements Bicycle
{
......
}

Inheritance: 
Object - oriented programming allows classes to inherit commonly used state and behavior from other classes. In Java, each class is allowed to to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses. 

class MountainBike extends Bicycle
{
...
}


No comments:

Post a Comment