Method Overriding

1. Program

//Find what it gives Compiletion Error / Compiletion Successfully / Output ?

class M { void test() { System.out.println("From M"); } } class N extends M { protected void test() { System.out.println("From N"); } public static void main(String[] args) { N n1 = new N(); n1.test(); System.out.println("Done"); } }

2. Program

//Find what it gives Compiletion Error / Compiletion Successfully / Output ?

class T { static void test() { } } class U extends T { void test() // must be static for Overriding { } }

3. Program

//Find what it gives Compiletion Error / Compiletion Successfully / Output ?

class V { void test() { } } class W extends V { static void test() // not static { } }

4. Program

//Find what it gives Compiletion Error / Compiletion Successfully / Output ?

class X { void test() { System.out.println("From x"); } } class Y extends X { void test() { System.out.println("From Y"); super.test(); System.out.println("done"); } public static void main(String[] args) { Y obj = new Y(); obj.test(); } }

Page....