Created
October 21, 2018 17:16
-
-
Save jeffrade/f3c024efee9cc0fafe1471e7392fa4a0 to your computer and use it in GitHub Desktop.
Java Abstract Class Instantiation and Overriding 101
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
/** | |
* Prints: | |
* creating A | |
* creating B | |
* in B print | |
*/ | |
public class Main { | |
public abstract class A { | |
public A() { | |
System.out.println("creating A"); | |
} | |
public void print() { | |
System.out.println("in A"); | |
} | |
} | |
public class B extends A { | |
public B() { | |
System.out.println("creating B"); | |
} | |
public void print() { | |
System.out.println("in B print"); | |
} | |
} | |
public static void main(String[] args) { | |
(new Main()).start(); | |
} | |
public void start() { | |
A b = new B(); | |
b.print(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment