Skip to content

Commit

Permalink
abstract demo: client class to access parent and child methods
Browse files Browse the repository at this point in the history
  • Loading branch information
NirmalSilwal committed Sep 4, 2020
1 parent f69d49e commit 310cccf
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions CodingBlocks Training/Day16/clientAbstract.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package Lecture16;

public class clientAbstract {

public static void main(String[] args) {

// not allowed
// parentAbstract obj = new parentAbstract(); // Cannot instantiate the type parentAbstract
// since parentAbstract class is abstract, you cannot make object of
// that class it can only be inherited

// not allowed
// childAbstract obj = new parentAbstract(); // Cannot instantiate the type parentAbstract

parentAbstract obj = new childAbstract();

obj.fun();
obj.fun1();
obj.fun2();

// not allowed as fun3() presence is checked in parentAbstract by compiler
// obj.fun3(); // The method fun3() is undefined for the type parentAbstract

System.out.println("=========================");

childAbstract obj2 = new childAbstract();

obj2.fun();
obj2.fun1();
obj2.fun2();
obj2.fun3();

}

}


/* output:
Inside child fun
Inside child fun1
Inside parent fun2
=========================
Inside child fun
Inside child fun1
Inside parent fun2
Inside child fun2
*/

0 comments on commit 310cccf

Please sign in to comment.