fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Person {
  8. private String name;
  9. private String addr;
  10. private char sex;
  11. private int age;
  12. //构造方法
  13. public Person(String n,String a,char s,int ag){
  14. this.setName(n);
  15. this.setAddr(a);
  16. this.setSex(s);
  17. this.setAge(ag);
  18. }
  19. public Person(String n,String a){
  20. setName(n);
  21. setAddr(a);
  22. }
  23. public Person(){
  24. }
  25. public void setName(String i){
  26. name=i;
  27. }
  28. public void setAddr(String i){
  29. addr=i;
  30. }
  31. public void setSex(char i){
  32. sex=i;
  33. }
  34. public void setAge(int i){
  35. age=i;
  36. }
  37. public String getName(){
  38. return name;
  39. }
  40. public String getAddr(){
  41. return addr;
  42. }
  43. public char getSex(){
  44. return sex;
  45. }
  46. public int getAge(){
  47. return age;
  48. }
  49. public void print(){
  50. System.out.println(this.getName()+this.getAddr()+this.getSex()
  51. +this.getAge());
  52. }
  53. }
  54.  
  55. /* Name of the class has to be "Main" only if the class is public. */
  56. class Ideone
  57. {
  58. public static void main (String[] args) throws java.lang.Exception
  59. {
  60. Person per=new Person("王默默","海南",'f',18);
  61. // your code goes here
  62. }
  63. }
Success #stdin #stdout 0.11s 320256KB
stdin
Standard input is empty
stdout
Standard output is empty