answersLogoWhite

0


Best Answer

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
This answer is:
User Avatar

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.

Related questions

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 *//} }


What is abstaction in java?

The concept of abstraction is concept talked about when talking about inheritance. When you make a class abstract, it means that the class is a general "abstract" idea, not something you want to instantiate (create an object from.) However, abstract classes are useful for when you want to create real sub-classes of the abstract class. For example, you could have an abstract class named "animal" that had the general characteristics of all animals, then you can have regular sub-classes that inherit "animal", like "dog", "cat" or "horse." The reason for making the "animal" class abstract is to make sure that one can't create a generic "animal" object, but so they can create objects that inherit the idea of "animal."


What is the purpose of declaring abstract method?

Abstract Class: The class which contains the common features of components of several classes, but cannot it be instantiated by itself. It represents an abstract concept for which there is no actual existing expression. For instance, "Vegetation" is an abstract class - there is no such real, real thing as generic vegetation. Instead, there are only instances of vegetation, such as mango tree and rose plant, which are types of vegetation, and share common characteristics, such as having leaves and stem in at least part of the lifecycle. SO in software engineering, an abstract class is a class in a nominative type system which is declared by the programmer, and which has the property that it contains members which are also members of some declared subtype. In many object oriented programming languages, abstract classes are known as abstract base classes, interfaces, traits, mixins, flavors, or roles. Note that these names refer to different language constructs which are (or may be) used to implement abstract types. We can also say that abstract class is : -- A class which is used only as an ancestor and is never instantiated. In other word a concrete definition will say that A type of class with pure virtual member functions and one or more methods that are declared but not implemented, that behaves as a base class but prohibits the instantiation of any members of that class. i.e. It has a complete interface but only a partial implementation It is used to take advantage of inheritance yet prohibiting the generation of objects that are not completely defined. Concrete subclasses of an abstract class are required to flesh out the implementation by overriding the abstract methods.


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 is abstract noun of real?

The abstract noun of real is "reality."


Is Elvis Presley an example of abstract noun?

No, the noun 'Elvis Presley' is an example of a concrete noun; a word for a person; the name of a real person.


What is abstract thearter?

abstract theareter is an actionin drama that shows real life


What is an abstract number?

An abstract number is a number with no context of application to real life objects or items.


What are some antonyms for abstract?

One antonym for abstract is concrete.Answer:actual, factual, material, objective, physical, real


What is the opposite word of abstract?

actual, real, factual


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.


Is an abstract representation of reality or of a real life situation?

I don't know what you're asking, really. But if you're asking if abstract ART represents reality or real life situations, i would say real life situations.