Inheritance, Polymorphism, Interface



*Inheritance-Is the capability of a class to use the properties and methods of another class while adding its own functionality. An example of where this could be useful is with an employee records system. You could create a generic employee class with states and actions that are common to all employees. Then more specific classes could be defined for salaried, commissioned and hourly employees. The generic class is known as the parent (or superclass or base class) and the specific classes as children (or subclasses or derived classes). The concept of inheritance greatly enhances the ability to reuse code as well as making design a much simpler and cleaner process.


>Super Class-
Any class above a specific class in the class hierarchy.
>Sub class

Any class below a specific class in the class hierarchy.
A subclass can also explicitly call a constructor of its immediate superclass. This is done by using the super constructor call. A super constructor call in the constructor of a subclass will result in the execution of relevant constructor from the superclass, based on the arguments pa
>Benefits of Inheritance

Benefits of Inheritance in OOP : Reusability– Once a behavior (method) is defined in a superclass, that behavior is automatically inherited by all subclasses. – Thus, you can encode a method only once and they can be used by all subclasses. – A subclass only needs to implement the differences between itself and the parent.
>Overriding Methods-

methods are methods that are redefined within an inherited or subclass. They have the same signature and the subclass definition is used.
If for some reason a derived class needs to have a different implementation of a certain method from that of the superclass, overriding methods could prove to be very useful. A subclass can override a method defined in its superclass by providing a new implementation for that method.
>Final Methods and Classes

Final Methods–
Methods that cannot be overridden
To declare final methods, we write,
public final [returnType] [methodName]([parameters]){. . .}
>Static methods are automatically final.

Final Classes
– Classes that cannot be extended
– To declare final classes, we write,
public final ClassName{. . . }
Example:
Other examples of final classes are your wrapper classes and Strings.
public final class Person { . . . }


*Polymorphism
– The ability of a reference variable to change behavior according to what object it is holding.– This allows multiple objects of different subclasses to be treated as objects of a single superclass, while automatically selecting the proper methods to apply to a particular object based on the subclass it belongs to.
Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. This is the third basic principle of object oriented programming. Overloading and overriding are two types of polymorphism . Now we will look at the third type: dynamic method binding.



>Abstract Classes
a class that cannot be instantiated. often appears at the top of an object-oriented programming class hierarchy, defining the broad types of actions possible with objects of all subclasses of the class.
*Interface
Interfaces are similar to abstract classes but all methods are abstract and all properties are static final. Interfaces can be inherited (ie. you can have a sub-interface). As with classes the extends keyword is used for inheritence.Java does not allow multiple inheritance for classes (ie. a subclass being the extension of more than one superclass). An interface is used to tie elements of several classes together. Interfaces are also used to separate design from coding as class method headers are specified but not their bodies. This allows compilation and parameter consistency testing prior to the coding phase. Interfaces are also used to set up unit testing frameworks.

Read Users' Comments (0)

Topics discussed in Java 1

1.Topics discussed in Java 1
>BufferedReader-Buffered input Stream Character
>Filereader-Input Stream that read from a file
>Basic elements of java
1.Application
2.Applet

Syntax rules- tell you which statements are legal or accepted and which are not.

Semantic rules- determine the meaning of the instructions.

Identifiers-are names of things are defined by user.

Class-is used to create a java program.

Method-is a set of instructions designed to accomplish a specific task.

Read Users' Comments (0)

Introduction to Java Programming

Introduction to Java Programming
a.History
The Java language has undergone several changes since JDK 1.0 as well as numerous additions of classes and packages to the standard library. Since J2SE 1.4, the evolution of the Java language has been governed by the Java Community Process (JCP), which uses Java Specification Requests (JSRs) to propose and specify additions and changes to the Java platform. The language is specified by the Java Language Specification (JLS); changes to the JLS are managed under JSR 901
.
In addition to the language changes, much more dramatic changes have been made to the Java class library over the years, which has grown from a few hundred classes in JDK 1.0 to over three thousand in J2SE 5.0. Entire new APIs, such as Swing and Java2D, have been introduced, and many of the original JDK 1.0 classes and methods have been deprecated
.

b.Java Technology

a. Programming language-is an artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine, to express algorithms precisely, or as a mode of human communication.
Many programming languages have some form of written specification of their syntax (form) and semantics (meaning). Some languages are defined by a specification document. For example, the C programming language is specified by an ISO Standard. Other languages, such as Perl, have a dominant implementation
that is used as a reference.
The earliest programming languages predate the invention of the computer, and were used to direct the behavior of machines such as Jacquard looms and player pianos. Thousands of different programming languages have been created, mainly in the computer field, with many more being created every year. Most programming languages describe computation in an imperative style, i.e., as a sequence of commands, although some languages, such as those that support functiona programming or logic programming
, use alternative forms of description.
b.Development Invironment- Development environment may refer to Integrated development environment.In hosted software (eg web site/application, database not shrinkwrap software) development, Development environment refers to a server tier designated to a specific stage in a release process.Development, staging
, and production is a common arrangement of tiers.
A more comprehensive list of tiers:

c.Application Invironment

d.Deployment Invironment

c.Java Features
-Java Virtual Machine
-Garbage Collection
-Code Security

Java 6 Features
feature or an enhancement in Java is encapsulated in the form of a JSR. JSR, which stands for Java Specification Request is nothing but a formal proposal which details the need for a specific functionality to be available in the Java Platform that can be used by Applications. These JSR’s will be reviewed and released by a committee called Java Expert Groups (JEG). This article covers the following list of features (or JSRs') that comes along with the Java 6 Platform.
>Pluggable Annotation Processing API (JSR 269)
>Common Annotations (JSR 250)
>Java API for XML Based Web Services - 2.0 (JSR 224)
>JAXB 2.0 (JSR 222)
>Web Services Metadata (JSR 181)
>Streaming API for XML (JSR 173)
>XML Digital Signature (JSR 105)
>Java Class File Specification Update (JSR 202)
>Java Compiler API (JSR 199)
>JDBC 4.0 (JSR 221)
>Scripting in the Java Platform (JSR 223)

d.The differrence between Java Application and Java Applet.

f.What makes Java an Object-Oriented-Programming Language.



Read Users' Comments (0)