Java SE 학습 노트 03 코드
/**
*
*/
package org.sean.module03;
/**
* ,
*
* , ,
*
* , , , ,
*
* : , , ( )
*
* ,
*
* ( ): , ,
*
* , 。
*
* : , ( )
*
* @author (Sean Yang)
*/
class Parent2 {
// ,Parent
public static String kind = "org.sean.module03.CoverAndHide.Parent";
// ,Parent
public static int age = 50;
// ,Parent
public String name = "Parent";
/** , Parent */
public static String getKind() {
System.out.println("parent getKind() method called");
return kind;
}
/** , Parent */
public static int getAge() {
System.out.println("parent getAge() method called");
return age;
}
/** , Parent */
public String getName() {
System.out.println("parent getName() method called");
return this.name;
}
}
class Child2 extends Parent2 {
// ,Child
public static String kind = "org.sean.module03.CoverAndHide.Child";
// ,Child
public static int age = 25;
// ,Child
public String name = "child";
/** , Child */
public static String getKind() {
System.out.println("child getKind() method called");
return kind;
}
/** , Child */
public static int getAge() {
System.out.println("child getAge() method called");
return age;
}
/** , Child */
public String getName() {
System.out.println("child getName() method called");
return this.name;
}
/** , Parent */
public String getParentName() {
return super.name;
}
/** , Parent */
public static String getParentKind() {
return Parent2.kind;
}
}
public class CoverAndHide {
@SuppressWarnings("static-access")
public static void main(String[] args) {
Child2 child = new Child2();
System.out.println("child name is " + child.name + ", child age is "
+ child.age + " ,kind is " + child.kind);// Child
/** Child Parent , */
// Parent2 parent = child;
Parent2 parent = new Child2();
System.out.println(" Parent name is " + parent.name + ", age is "
+ parent.age + " ,kind is " + parent.kind);
/**
* :
*
* ( ), ,
*
* , "super. "
*
* , " . "
*/
System.out.println(" :" + child.getParentName());
System.out.println(" :" + child.getParentKind());
/** */
child.getName();
child.getKind();
parent.getName();
parent.getKind();
/**
* :
*
* , ( )
*
* ( ), ,
*/
}
}
부모 클래스 와 하위 클래스 로 딩 순서 에 대한 코드
/**
*
*/
package org.sean.module03;
/**
* ---> ---> ---> ---> --->
*
* ,
*
* @author (Sean Yang)
*/
class Parent1 {
@SuppressWarnings("unused")
private int x = 50;
static {
System.out.println("parent static block");
}
@SuppressWarnings("unused")
private static int sx = getNext(99);
{
System.out.println("parant init block");
}
public Parent1() {
System.out.println("parent constructor");
}
public static int getNext(int base) {
System.out.println("static parameter initialized");
return ++base;
}
}
class Child1 extends Parent1 {
static {
System.out.println("child static block");
}
{
System.out.println("child init block");
}
public Child1() {
System.out.println("child constructor");
}
}
public class LoadingOrder {
public static void main(String[] args) {
@SuppressWarnings("unused")
Child1 child = new Child1();
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.