tags:

views:

175

answers:

3

what are the differences of Inheritance & java Beans?

+2  A: 

Inheritance is a general object oriented programming concept whereby one type can be of the same type as another object but introduce new properties and behaviors (i.e. a Lion class could inherit from a Mammal class) while JavaBeans are just Java objects that adhere to a set of conventions. From Wikipedia:

  • The class must have a public default constructor. This allows easy instantiation within editing and activation frameworks.

  • The class properties must be accessible using get, set, and other methods (so-called accessor methods and mutator methods), following a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties.

  • The class should be serializable. This allows applications and frameworks to reliably save, store, and restore the bean's state in a fashion that is independent of the VM and platform.

BobbyShaftoe
Good answer to a bad question!
Elijah
Upvoting for having the patience to give a good answer here.
Zarkonnen
Thanks guys :)
BobbyShaftoe
+1  A: 

Not sure what you mean, but when people talk about beans vs. inheritance it usually means naming convention vs. inheritance.

Bean defines it's properties using matching get and set methods, and also optionally using BeanInfo, so the properties are then accessed using introspection (reflection). When objects extends a class or implements an interface, on the other hand, the properties/methods are accessed via that interface (superclass).

HTH.

Yardena
A: 

A Java Bean is a simple class which contains some properties (i.e. data elements) and "getters and setters" (getProperty1(), setProperty1(myValue)) to read and write those properties.

Inheritance is an Object Oriented principle in which one class exhibits the properties and behaviours of another. It is said to inherit from the other class.

Richard Nichols
"principle", you mean, not principal.
talonx