}
interface CanSwim{
void swim();
}
interface CanFly{
void fly();
}
class ActionCharacter{
public void fight(){}
}
class Hero extends ActionCharacter implements CanFight,CanSwim,CanFly{
@Override
public void fly() {}
@Override
public void swim() {}
}
public class Adventure {
public static void t(CanFight x){
x.fight();
}
public static void u(CanSwim x){
x.swim();
}
public static void v(CanFly x){
x.fly();
}
public static void w(ActionCharacter x){
x.fight();
}
public static void main(String[] args) {
Hero h = new Hero();
t(h);
u(h);
v(h);
w(h);
}
}
interface DangerousMonster extends Monster{
void destroy();
}
interface Lethal{
void kill();
}
class DragonZilla implements DangerousMonster{
public void menace(){}
public void destroy(){}
}
interface Vampire extends DangerousMonster,Lethal{
void drinkBlood();
}
class VeryBadVampire implements Vampire{
public void menace(){}
public void destroy(){}
public void kill(){}
public void drinkBlood(){}
}
public class HorrorShow {
static void u(Monster b){
b.menace();
}
static void v(DangerousMonster d){
d.menace();
d.destroy();
}
static void w(Lethal l){
l.kill();
}
public static void main(String[] args) {
DangerousMonster barney = new DragonZilla();
u(barney);
v(barney);
Vampire vlad = new VeryBadVampire();
u(vlad);
v(vlad);
w(vlad);
}
}
interface I2{
int f(int i);
}
interface I3{
int f();
}
class C{
public int f(){
return 1;
}
}
class C2 implements I1,I2{
public void f(){}
public int f(int i){
return 1;
}
}
class C3 extends C implements I2{
public int f(int i){
return 1;
}
}
class C4 extends C implements I3{
public int f(){
return 1;
}
}
//class C5 extends C implements I1{}
private static final char[] capitals="ABCDEFJ".toCharArray();
private static final char[] lowers="abcdefj".toCharArray();
private static final char[] vowels="aeiou".toCharArray();
private int count;
public RandomWords(int count){
this.count=count;
}
@Override
public int read(CharBuffer cb) throws IOException {
if(count--==0){
return -1;
}
cb.append(capitals[rand.nextInt(capitals.length)]);
for(int i=0;i<4;i++){
cb.append(vowels[rand.nextInt(vowels.length)]);
cb.append(lowers[rand.nextInt(lowers.length)]);
}
cb.append(" ");
return 10;
}
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner s = new Scanner(new RandomWords(10));
while(s.hasNext()){
System.out.println(s.next());
}
}
Aofebudof
Aoaaaiaoa
Fajudaeia
Jucaeeaif
Aaeediauf
Aufibibud
Duaaeeaid
Jududoaod
public double next(){
return rand.nextDouble();
}
public static void main(String [] args){
RandomDoubles rd = new RandomDoubles();
for(int i=0;i<7;i++){
System.out.println(rd.next());
}
}
0.5309454508634242
0.16020656493302599
0.18847866977771732
0.5166020801268457
0.2678662084200585
public AdaptedRandomDouble(int count){
this.count=count;
}
@Override
public int read(CharBuffer cb) throws IOException {
if(count--==0){
return -1;
}
String result=Double.toString(next())+" ";
cb.append(result);
return result.length();
}
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner s = new Scanner(new AdaptedRandomDouble(7));
while(s.hasNextDouble()){
System.out.println(s.nextDouble());
}
}
0.5309454508634242
0.16020656493302599
0.18847866977771732
0.5166020801268457
0.2678662084200585
JANUARY=1,FEBRUARY=2,MARCH=3;
int RANDOM_INT=RAND.nextInt(10);
long RANDOM_LONG=RAND.nextLong()*10;
float RANDOM_FLOAT=RAND.nextLong()*10;
double RANDOM_DOUBLE=RAND.nextDouble()*10;
public static void main(String[] args) {
System.out.println(RandVals.RANDOM_INT);
System.out.println(RandVals.RANDOM_LONG);
System.out.println(RandVals.RANDOM_FLOAT);
System.out.println(RandVals.RANDOM_DOUBLE);
}
-32032247016559954
-8.5939291E18
interface B{
void f();
}
public class BImp implements B{
public void f(){}
}
private class BImp2 implements B{
public void f(){}
}
public interface C{
void f();
}
class CImp implements C{
public void f(){}
}
private class CImp2 implements C{
public void f(){}
}
private interface D{
void f();
}
private class DImp implements D{
public void f(){}
}
public class DImp2 implements D{
public void f(){}
}
public D getd(){
return new DImp2();
}
private D dRef;
public void receiveD(D d){
dRef=d;
dRef.f();
}
}
interface E{
interface G{
void f();
}
public interface H{
void f();
}
void g();
// private interface I{}
}
public class NestingInterfaces {
public class BImp implements A.B{
public void f(){}
}
class CImp implements A.C{
public void f(){}
}
// class CImp implements A.D{
// public void f(){}
// }
class EImp implements E{
public void g(){}
}
class EGImp implements E.G{
public void f(){}
}
class EImp2 implements E{
public void g(){}
class EG implements E.G{
public void f(){}
}
}
public static void main(String[] args) {
A a = new A();
// A.D getd = a.getd();
// A.DImp2 di2=a.getd();
// a.getd().f();
A a2 = new A();
a2.receiveD(a.getd());
}
void method2();
}
interface ServiceFactory{
Service getService();
}
class Implementation1 implements Service{
public Implementation1() {}
public void method1(){
System.out.println("Implementation1 method1");
}
public void method2(){
System.out.println("Implementation1 method2");
}
}
class Implementation1Factory implements ServiceFactory{
public Service getService(){
return new Implementation1();
}
}
class Implementation2 implements Service{
public Implementation2() {}
public void method1(){
System.out.println("Implementation2 method1");
}
public void method2(){
System.out.println("Implementation2 method2");
}
}
class Implementation2Factory implements ServiceFactory{
public Service getService(){
return new Implementation2();
}
}
public class Factories {
public static void serviceConsumer(ServiceFactory fact){
Service s = fact.getService();
s.method1();
s.method2();
}
public static void main(String[] args) {
serviceConsumer(new Implementation1Factory());
serviceConsumer(new Implementation2Factory());
}
}
interface GameFactory{
Game getGame();
}
class Checkers implements Game{
private int moves=0;
private static final int MOVES=3;
public boolean move(){
System.out.println("Checkers move"+moves);
return ++moves!=MOVES;
}
}
class CheckersFactory implements GameFactory{
public Game getGame(){
return new Checkers();
}
}
class Chess implements Game{
private int moves=0;
private static final int MOVES=4;
public boolean move(){
System.out.println("Chess move"+moves);
return ++moves!=MOVES;
}
}
class ChessFactory implements GameFactory{
public Game getGame(){
return new Chess();
}
}
public class Games {
public static void playGame(GameFactory factory){
Game game = factory.getGame();
while(game.move());
}
public static void main(String[] args) {
playGame(new CheckersFactory());
playGame(new ChessFactory());
}
Checkers move1
Checkers move2
Chess move0
Chess move1
Chess move2
1万+



被折叠的 条评论
为什么被折叠?



