public class TestOuter { public static class TestInner {
public void sayIt(){ System.out.println("hello"); } }
public static void main(String[] args){
//call here
} }
Why TestInner.sayIt(); cannot be the the second answer?
About Question enthuware.ocpjp.v11.2.3503 :
Moderator: admin
-
- Posts: 1
- Joined: Sat Aug 15, 2020 6:37 pm
- Contact:
-
- Site Admin
- Posts: 9753
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3503 :
As the explanation for this options says:
You can actually try it out.TestInner is static but its method sayIt is not. So, you need to do new TestInner().sayIt(); in main to invoke sayIt.
If you like our products and services, please help us by posting your review here.
-
- Posts: 19
- Joined: Thu Dec 09, 2021 11:23 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3503 :
Hello, question:
new TestOuter.TestInner() -> are we using this call because TestInner is static? Thanks
new TestOuter.TestInner() -> are we using this call because TestInner is static? Thanks
-
- Site Admin
- Posts: 9753
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3503 :
Yes, that is correct. Just like you refer to any other static member of a class.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 1 guest