ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل PREMKUMAR GANGATHARAN , test engineer trainee , clorida infotech
تاريخ النشر: 2013/12/21
Hatim Laxmidhar
من قبل 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.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟