Method Overriding in Java

 package com.company;


class A {
public int a;

public int aryan() {
return 3;
}

public void meth2() {
System.out.println("I am method 2 of class A");
}
}
class B extends A{
@Override
public void meth2() {
System.out.println("I am method 32 of class B");
}
public void meth3() {
System.out.println("I am method 3 of class B");
}
}


public class tuts {
public static void main(String[] args) {
A a = new A();
a.meth2();
B b = new B();
b.meth2();

}
}

Comments

Popular posts from this blog

Creating a Thread by Extending Thread class

Constructors from Thread class in Java