Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040201&docId=69740211&qb=7J6Q67CUIOyduO2EsO2OmOydtOyKpCDstpTsg4HtgbTrnpjsiqQ=&enc=utf8§ion=kin&rank=4&search_sort=0&spq=0
- // Regular class inheritance
- package com.peter.inheritance;
- public class Main {
- public static void main(String[] args) {
- Son ObSon = new Son();
- ObSon.func();
- ObSon.father_func(); // inheritance from Father class
- Father ObFather = new Father();
- ObFather.func();
- }
- }
- ------------------
- package com.peter.inheritance;
- public class Father {
- public void func() {
- System.out.println("Father");
- }
- public void father_func() {
- System.out.println("Father_Func");
- }
- }
- -------------------
- package com.peter.inheritance;
- public class Son extends Father {
- public void func() { // Overriding
- System.out.println("Son");
- }
- }
- // Abstract class inheritance
- package com.peter.inheritance;
- public class Main {
- public static void main(String[] args) {
- Son ObSon = new Son();
- ObSon.func();
- }
- }
- -----------------------------
- package com.peter.inheritance;
- abstract class Father {
- abstract void func();
- }
- ----------------------------
- package com.peter.inheritance;
- public class Son extends Father {
- public void func() { // Overriding not Needed!!
- System.out.println("Son");
- }
- }
- // Interface class inheritance
- package com.peter.inheritance;
- public class Main {
- public static void main(String[] args) {
- Son ObSon = new Son();
- ObSon.func();
- }
- }
- -------------------------------
- package com.peter.inheritance;
- public interface Father {
- abstract void func();
- }
- -----------------------------
- package com.peter.inheritance;
- public class Son implements Father {
- public void func() { // Overriding Needed!!
- System.out.println("Son");
- }
- }
- // Anonymous Inner Class Inheritance
- package com.peter.inheritance;
- public class Main {
- public static void main(String[] args) {
- Son ObSon = new Son(){ // Inner Class
- public void func(){ // Method Overriding
- System.out.println("Main");
- }
- };
- ObSon.func();
- }
- }
- -------------------------------
- package com.peter.inheritance;
- public interface Father {
- abstract void func();
- }
- -----------------------------
- package com.peter.inheritance;
- public class Son implements Father {
- public void func() { // Overriding Needed!!
- System.out.println("Son");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment