- package com.oops;
- class A
- {
- void msg(){
- System.out.println("Hello");
- }
- }
- class B extends A
- {
- void msg(){
- System.out.println("Welcome");
- }
- public static void main(String args[])
- {
- A a=new A();
- B b=new B();
- A obj=new B();
- System.out.println(a.msg()); // Hello
- System.out.println(obj.msg()); // Welcome
- System.out.println(b.msg()); //Welcome
- }
- }
Output:
- Hello
- Welcome
- Welcome
all examples are easily understanding
ReplyDelete