answersLogoWhite

0

w.frnds........

I am just trying to an example of abstract class and interface class in real life . As these two

["interface class" is not a term in Java programming - just "interface"]

classes [sic] are a concept of objest orientation so easy we can easily compare thhese with our real life .

Suppose we have an abstract class called clark and an abstract method behabour of this abstract class ,which has no definition in abstract class.

two other class security and receptionist inherits these clark class.

So in thses two derived class there must has to be a defonation of behabour method,which depends on the derived class which types of behabour they will show........

So that is a real life example of Abstract class .Interface is also same as abstract class only the difference is it can't contain any implementation of any method in base class or super class.

I think this is a sufficient example to understand abstract class and interface.

[No, it is not sufficient.]

If u have any doubt then u can contact me with this email id-rkmahanta26@gmail.com

[Interfaces support multiple inheritance; classes do not. Interfaces contain only public members; classes do not have to. Interfaces do not have superclasses, except the implicit 'Object' supertype; they have superinterfaces. Nested interfaces are always static, never inner, unlike classes which can be inner classes. "u" is not an English pronoun.

Use the tutorial and the JLS to understand interfaces and abstract classes, not this garbage answer.]

User Avatar

Wiki User

9y ago

Still curious? Ask our experts.

Chat with our AI personalities

ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
ProfessorProfessor
I will give you the most educated answer.
Chat with Professor
ReneRene
Change my mind. I dare you.
Chat with Rene

Add your answer:

Earn +20 pts
Q: Real time example for interface vs abstract class in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can anyone 1 pls give a real time example and usage of abstract class and interface in c sharp?

Abstract classes and Interfaces are both examples of contracts with no default implementation. Interfaces are more readily interchangeable between applications (because they can be interpreted as jump tables). Because of this COM in Windows makes heavy usage of interfaces with several master ones being the source of all functionality (e.g., IUnknown). If a programmer wanted to define a type of thing (e.g., MusicalInstrument), that had certain abilities (e.g. Play) without defining how a MusicalInstrument plays... This could be done with an Interface or an Abstract class. If the programmer wanted to provide some base functionality to whomever was going to implement this functionality (e.g., Vloume, Output Stream) then this would be more appropriate for an Abstract class. Abstract classes can even build on interfaces: public interface IMusicalInstrument { void Play(); } public abstract class MusicalInstrument:IMusicalInstrument { private int vol = 10; public virtual SetVolume(int newVol){vol = newVol;} public abstract void Play(); } public class Horn:MusicalInstrument { public override void Play(){//* Play something *//} }


Do abstract classes and pure virtual functions have practical value in the real world?

Yes. An abstract class is a conceptual class (an incomplete class) that provides a generic interface for two or more actual classes (the derived classes). For instance, a shape is not an actual object, nor is a mammal. They are simply a type of object; a conceptual object. A square is an actual type of shape, just as a golden Labrador is a specific breed of dog, an actual mammal. The conceptual classes merely provide a generic interface to the actual object, but do not have enough information to implement that interface. For instance, all shapes can be drawn, but without knowing what type of shape to draw, the conceptual shape cannot implement the draw method, it can only provide the interface. By declaring the shape::draw method to be pure-virtual, you not only ensure that you cannot instantiate a shape by itself (it is merely an abstraction), you also ensure that all the derivatives of the shape class provide a specific implementation of that interface.


What are the applications of An Abstract Class in c plus plus?

An abstract class is a class that has a pure virtual function. A pure virtual function can be used in a base class if the function that is virtualised contains parameters that can and should be interchangeable, but the function should remain intact. For example, there is a base class Object in a game that will contain movement for simple objects, but the movement function may need to use different parameters per object.


How do you convert integer to objects in c?

There are no objects in C, so you can't. However, in C++ you can convert an integer to an object if the object's class exposes a public conversion constructor that accepts an integer argument. For example: class X { public: X (int); // conversion constructor // ... }; How the conversion is implemented depends on the class designer. In the following example, a user can construct a complex number type from an integer: class complex { private: double r; double i; public: complex (double real, double imaginary): r {real}, i {imaginary} {} complex (int real): r {real}, i {0.0} {} // ... }; Here, the implementation implicitly converts the integer to a double and assigns that value to the real representation and assigns the value 0.00 to the imaginary representation. This class may be used as follows: complex c = 42; // e.g., c.r = 42.0, c.i = 0.0 If a conversion constructor is provided, a corresponding conversion assignment is usually provided as well: class complex { private: double r; double i; public: complex (double real, double imaginary): r {real}, i {imaginary} {} complex (int real): r {real}, i {0.0} {} complex& operator= (int real) { r = real; i = 0.0; } // ... }; This class may be used as follows: complex c {1.1, -3.14}; // ... c = 42; // e.g., c.r = 42.0, c.i = 0.0


What is the Need for structure in c plus plus?

There is no pressing need for structures in C++. Anything you can do with a structure you can also do with a class. The only real difference is that structure members are public by default, whereas class members are private by default, but they both work exactly the same way otherwise. The struct keyword is retained for backward compatibility with C, but a C++ struct is not the same as a C struct unless it is has no interface and all the member variables are implicitly public. Most C++ programmers will use structures to differentiate simple data structures (values) from fully-encapsulated classes (objects). The complexity of the data and its interface is usually the deciding factor in whether to use a class or a structure. For trivial classes the time and effort that goes into developing the interface is often unnecessary so a structure will often suffice. But if the class is to be distributed to third parties then it's better to provide a more robust interface, even for trivial classes, and to avoid C-style structures entirely.