Search This Blog

Tuesday 19 April 2011

Interface

Interface:
An interface in the java programing is an abstract type.
Interface can have variables and methods.
variables in interface are final,means the variables are constant,
and the methods dont have any definition.
An interface is declared as
interface interfacename
{
//variables
//method names with out any body definition
}
For an interface we cannot create any object for it.
If we want to create object we need to implement this interface through a class.
and the implemting class should all the methods in interface if not the class becomes abstract.
An interface can implement another interface also.


Thursday 14 April 2011

Types of Inheritance

1.Simple inheritance
Simple inhertance means one class extends the the class
Example
Class B extends A
B is the sub class and A is sub class
2.Multiple inheritance
Java implements multiple inheritance through interfaces but not through classes
multiple inheritance example
interface A
interface B
class C implements B,A
so multiple inheritance means one class can have one or more super classes.
3.Hybrid inheritance:
Suppose take an example
class A
class B extends A
class C extends B
means here class C has two super class B inturn B has a super class A
Advantages of inheritance
Main advantage of inheritance is code reusability
means the code in one class can be reused with out writing the code again.

Wednesday 13 April 2011

Inheritance

This is one of the important Oops. concept.
what is inheritance:
Aquiring the properties of one object class to another object class is called inheritance.
Means suppose take an example of  mother and child,some of the mother features will come to child.
Like this only in java suppose take class A it contains a variable test as int data type.
and a method function as display with return type void.
now take another class B it extends Class A means A is super class and now B is subclass
now B class will contain variable test and function display.
syntax of this is as follows......
Class A
{
//variables and functions
}

Class B extends A
{
//you can add your own functions also here
}
I will post the types of inheritance in my next post...

Class

A class is a blueprint or prototype from which objects are created.
In a class we can have class variables and methods.
Through these methods we can do operations on variables as per the requirement.
A class can be public private.
public class can access outside the package also but not the private class
A class can be abstract, final static.

Friday 8 April 2011

Hai

If any doubts pls post ur questions,
i will try to solve it....