Upward transformation of Inner Class

xiaoxiao2021-03-06  72

Upward transformation of Inner Class

When an Inner Class object is turned upward into interface, we get just a reference.

Interface destination {

String readlabel ();

}

Interface contents {

Int value ();

}

Class pacel3 ​​{

Private

Class PContents

Implements contents {

Private

INT i = 11;

public

Int value () {

Return I;

}

protected

Class PDestination

Implements destination {

PRIVATE STRING LABEL;

PDestination (String WHereto) {

Label = WHERETO;

}

Public string readlabel () {

Return label;}

}

Public Destination to (String s) {

Return

New pdestination (s);

}

Public contents last () {

Return

New PContents ();

}

}

public

Class expectitstatic {

public

Static

Void main (string [] args) {

PARCEL3 P =

New paracel3 ​​();

// Transform the Inner Class object upward

CONTENTS C = P.cont ();

Destination D = P.to (

"Borneo");

}

}

Although we can't call PContents Class in the ExplicitStatic Class, we can call a PContents Class object to Contents to CONTENTS.

转载请注明原文地址:https://www.9cbs.com/read-121315.html

New Post(0)