JAVA OVERRIDING

/*you can say This is the condition of override…
1.The main condition “Must be has different class”
2.must be overloading
3.if and only if method name,return type and also parameter are same then occurs override.otherwise impossible to happen override
OK.Fine.now we can see a method override program….

class A
{
String name;
int i,j;
A()
{
System.out.println(“Hi!”);
}
A(String name) //A method overloading
{
System.out.println(“How are you…?”);
}

Remember please…method overloading and method overriding is a example of Polymorphism*/


void show()
{
System.out.println(“I think you are ok.”);
}
void show(int i) //show method overloading
{
System.out.println(“you understand that life is so beautiful…”);
}
void show(String name)
{
System.out.println(“time and tide wait for none”);
}
void method()
{
System.out.println(“If you realized carefully…”);
}
}

class B extends A
{
String name;
int i,j,k;
B()
{
System.out.println(“we enter a new class of B..”);
}
B(int i)
{
System.out.println(“welcome to our new class…”);
}
void show() //show method overriding
{
System.out.println(“if you really study hard you will………”);
}
void show(int k) //show method overloading
{
System.out.println(“Ok.i am so tried..write to this latar.”);
}
void method() //method method overriding
{
System.out.println(“method overloaded here “);
}
}

public class C extends B
{
int i,j,k;
C()
{
System.out.println(“method of c”);
}
public static void main(String args[])
{
System.out.println(“Hello…”);
C ob = new C(); //here print all three classes default constructor method .it’s rules
ob.show(); //call a show method,and it taken B classses show method
ob.show(4); //here call a show method and taken A classes show method..bez show(int i) has A class
ob.show(“rana”); /*here printed A classes show method..we have to know that,if any method which i creat and call,if these method no stay
current classes extended classes then it look where this method have and if same then print these method*/
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *