Runtime Polymorphism / Rule -2

PHOTO EMBED

Wed Apr 26 2023 17:56:41 GMT+0000 (Coordinated Universal Time)

Saved by @Shankar #instanceblocks #inheritance #overloading


class Parent
{
	int ml(){
	System.out.println("Parent m1");
	return 200;
}
}
class Child extends Parent
{
	int m1(){
	System.out.println("Child m1");
		return 100;
		}
}
class Demo 
{
	public static void main(String[] args) 
	{
		System.out.println("Hello Wo");
		Child c1 = new Child();
		int a=c1.m1(); 
		
		// you are returning Parameters 
		//type int so Both Parent and Child method return type is same as primitive level.
		// ex boolean m1()- true
		//    boolean m1() - false is same as data type
		
		System.out.println(a);
	}
}
content_copyCOPY