-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
abstract demo: client class to access parent and child methods
- Loading branch information
1 parent
f69d49e
commit 310cccf
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |