人生若只如初见~
好久没写简单的代码了~唉~
import java.util.Scanner; public class Main { public static void main(String[] args){ Man man = new Man(); Woman woman = new Woman(); Robot robot = new Robot(); Scanner scanner = new Scanner(System.in); String flag = scanner.next(); if(flag.equals("M")){ man.MakePerson(); } else if (flag.equals("W")) { woman.MakePerson(); }else{ robot.MakePerson(); } } }
public interface Nvwa { //这里呢可以先定义一个接口 void MakePerson(); }
public class Man implements Nvwa{ @Override public void MakePerson() { System.out.println("女娲造Man!"); } }
public class Woman implements Nvwa{ @Override public void MakePerson() { System.out.println("女娲造Woman!"); } }
public class Robot implements Nvwa{ @Override public void MakePerson() { System.out.println("女娲造Robot!"); } }