daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 52 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. public class OverLoad {
  2.     //重载是在一个类里面,方法相同,而参数不同,返回类型可以相同也可以不同。
  3.     public static void main(String[] args){
  4.         new Teacher();
  5.         new Teacher("lisi");
  6.         new Teacher("wangwu",28,3210.0);
  7.         new Teacher(34,40000.0,"liming");
  8.     }
  9. }
  10. class Teacher{
  11.     String name;
  12.     int age;
  13.     String subject;
  14.     double salary;
  15.     public void Info(){
  16.         System.out.println("name:" + name+"\tage"+age+"\tsalary"+salary);
  17.  
  18.     }
  19.  
  20.     //不带初始化方法,赋常量值
  21.     public Teacher(){
  22.         this.initTeacher();
  23.         this.Info();
  24.     }
  25.     public Teacher(String name){
  26.         this.initTeacher(name);
  27.         this.Info();
  28.     }
  29.     public Teacher(int age){
  30.         this.initTeacher(age);
  31.         this.Info();
  32.     }
  33.     public Teacher(String name,int age,double salary){
  34.         this.initTeacher(name,age,salary);
  35.         this.Info();
  36.     }
  37.     public Teacher(int age,double salary,String name){
  38.         this.initTeacher(age,salary,name);
  39.         this.Info();
  40.     }
  41.     public void initTeacher(){
  42.         System.out.println("不带初始化的方法,赋常量值");
  43.         this.name = "zhangsan";
  44.         this.age = 28;
  45.         this.subject = "数学";
  46.         this.salary = 2350.0;
  47.     }
  48.     public void initTeacher(String name){
  49.         System.out.println("带一个String参数");
  50.         this.name = name;
  51.     }
  52.     public void initTeacher(int age){
  53.         System.out.println("带一个age参数");
  54.         this.age = age;
  55. }
  56. public void initTeacher(String name,int age,double salary){
  57.         System.out.println("带三个参数的");
  58.         this.name= name;
  59.         this.age = age;
  60.         this.salary = salary;
  61.  
  62. }
  63. public void initTeacher(int age,double salary,String name){
  64.         System.out.println("带三个参数的顺序不同");
  65.         this.name = name;
  66.         this.age = age;
  67.         this.salary = salary;
  68. }
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top