A
类Biycle:
protected String speed;
private int id;
本类中调用main方法:
Biycle bi = new Biycle();
Biycle mb = new MountBiycle();
System.out.println(mb.id);
System.out.println(bi.id);//private实际上是文件访问权限控制,本类这个文件中可以访问
子类:MountBiycle
private String height;
子类中main方法:
MountBiycle mb = new MountBiycle();
System.out.println(mb.speed);
Biycle bi = new Biycle();
System.out.println(bi.speed);//id属性是父类Biycle私有,子类没有继承,并且脱离Biycle类不能够访问
B
public abstract class Animal
{
public void identifyMyself()
{
System.out.println("I am an animal");
}
public static void getName()
{
System.out.println("Animal");
}
}
热门评论
public static void main(String[] args) throws NoSuchMethodException, SecurityException
{
List<Person> roster = new ArrayList<>();
roster.add(new Person("密码",LocalDate.parse("2001-11-10"),Person.Sex.MALE));
roster.add(new Person("牛奶",LocalDate.parse("1998-07-23"),Person.Sex.FEMALE));
roster.add(new Person("diss",LocalDate.parse("2001-01-22"),Person.Sex.MALE));
// printPersons(roster, p -> p.getAge() >15 );
// printPersons(roster, p -> p.getAge() >15
// && p.gender==Person.Sex.FEMALE );
}
import java.lang.reflect.Method;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
public class Administrator
{
// static void printPersons(List<Person> roster,CheckPerson checker)
// {
// for(Person p : roster)
// {
// if(checker.test(p))
// {
// p.printPerson();
// }
// }
// }
static void printPersons(List<Person> roster,Predicate<Person> predicater)
{
for(Person p : roster)
{
if(predicater.test(p))
{
p.printPerson();
}
}
}
/**
* functional interface
* java.util.function中提供了几个函数式接口Predicate、Consumer、Function
*/
public interface CheckPerson
{
boolean test(Person p);
default int getAge(int year)
{
return year-1;
}
default String getName(String name)
{
return "name = "+name;
}
}