About Question enthuware.ocpjp.v8.2.1751 :
Posted: Mon Apr 12, 2021 6:34 am
I tested
Make the isFiction method in BookFilter class static and replace LINE 10 with:this works if the main() is in the Book class...
When I move the main() into a different class in the same package,but I try
and was expecting this to work, but it does not...
I know that when you have a nested static class, you cannot create it with instance of the outer class
but I don't understand why this wouldn't work?
any explanation for ***?
Make the isFiction method in BookFilter class static and replace LINE 10 with:
Code: Select all
.filter((Book b)->new BookFilter().isFiction(b)) //also works...
When I move the main() into a different class in the same package,
Code: Select all
.filter((Book b)->new BookFilter().isFiction(b)) //NOT COMPILE
Code: Select all
.filter((Book b)->Book.new BookFilter().isFiction(b)) //NOT COMPILE *** even if the main() is in Book
I know that when you have a nested static class, you cannot create it with instance of the outer class
but I don't understand why this wouldn't work?
any explanation for ***?