Tuesday, August 21, 2012

Explain the difference between abstract class and interfaces with an example for each.


Explain the difference between abstract class and interfaces with an example for each.

The differences between abstract class and interface are as follows:
Abstract Class
Interface
Can have abstract methods and concrete methods
Can have only method signatures and static final members
All methods are not by default public
All methods by default abstract and public
An abstract class can extend another abstract class
An interface can extend another interface but not a class
The extended class can override the methods of its super class and its hierarchy
An implementing class can implement multiple interfaces
All abstract methods must have abstract access modifier
All methods in an interface must not have abstract access modifier
The following examples illustrate the differences:
abstract class Shape
{
       abstract void area();
       abstract void perimeter();
       void someMethod() // concrete method
       {
              ..
       }
}

interface Shape
{
       void area();
       void perimeter();
}


// amazon ebay shopbob.com hotels.com canon newegg.com 

Java Quick Program

1. Write a Code to generate Random numbers public class GenerateRandomNumbers { public static void main(String[] args) { System.out...