Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.peter.inheritance;
- public class Main {
- public static void main(String[] args) {
- new Son().func1(); // Anonymous Inner Class
- Son ObSon = new Son();
- ObSon.func2();
- new Son().func2();
- new Son() { // Anonymous Inner Class
- public void func2() { // Overriding func2()
- System.out.println("Main");
- }
- }.func2();
- }
- }
- -----------------------------------------
- package com.peter.inheritance;
- public interface Father {
- String data = "Father";
- abstract void func();
- }
- -----------------------------------------
- package com.peter.inheritance;
- public class Son implements Father {
- public void func(){}; // Needed for override!!
- public void func1() {
- new Father() { // Anonymous Inner Class
- public void func() {
- System.out.println(data);
- }
- }.func();
- } // Description of Method "test()"
- public void func2(){
- System.out.println("Son");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment