标签:ring 完成 on() 个数 index 技术分享 over 顺序 idt
方法重载Overload是指:多个方法的方法名相同,但各自的参数不同
public static void main(String[] args) {
String s = "Test";
int n1 = s.indexOf(‘e‘);//返回字符的索引
int n2 = s.indexOf("st");//返回字符串的索引
int n3 = s.indexOf(‘t‘, 2);//从index=2处开始,返回字符的索引
int n4 = s.indexOf("st", 3);//从index=3开始,返回字符的索引。无结果返回-1
System.out.println(n1);
System.out.println(n2);
System.out.println(n3);
System.out.println(n4);
}
Person.java
public class Person {
private String name;
public void setName(String name) {
this.name = name;
}
public void setName(String firstName,String lastName) {
this.name = firstName+lastName;
}
public void setName(String firstName, String middleName,String lastName) {
this.name = firstName+ middleName +lastName;
}
public String getName() {
return name;
}
}
Hello.java
public class Hello {
public static void main(String[] args) {
Person ming = new Person();
ming.setName("小明");
System.out.println(ming.getName());
Person hong = new Person();
hong.setName("李","红");
System.out.println(hong.getName());
Person wang = new Person();
wang.setName("王","宝","强");
System.out.println(wang.getName());
}
}
标签:ring 完成 on() 个数 index 技术分享 over 顺序 idt
原文地址:https://www.cnblogs.com/csj2018/p/10263377.html