Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Can you tell me one real time example for interface and abstract class?

user-image
Question ajoutée par PREMKUMAR GANGATHARAN , test engineer trainee , clorida infotech
Date de publication: 2013/12/21
Hatim Laxmidhar
par Hatim Laxmidhar , Self Employed , The Way It Works

Example:

A Vehicle can be an interface with a method. 

MotorVehicle and Aircraft  are abstract classes.

Car, Bus etc are subclass of MotorVehicle.

Airbus, Cargo Planes, fighter planes are subclass of aircraft.

 

As per http://docs.oracle.com

In the Java programming language, an interface is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods. Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces.

Abstract classes are similar to interfaces. You cannot instantiate them, and they may contain a mix of methods declared with or without an implementation. However, with abstract classes, you can declare fields that are not static and final, and define public, protected, and private concrete methods. With interfaces, all fields are automatically public, static, and final, and all methods that you declare or define (as default methods) are public. In addition, you can extend only one class, whether or not it is abstract, whereas you can implement any number of interfaces.

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?