Hi,
What do you mean by: "The instanceOf operator does not take of the outer instance into consideration"? Could you please make an actual example?
Thanks in advance.
The_Nick.
About Question enthuware.ocpjp.v7.2.1521 :
Moderator: admin
-
- Posts: 132
- Joined: Thu May 16, 2013 9:23 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1521 :
Code: Select all
public class TestClass {
class Inner{
}
public static void main(String[] args){
TestClass.Inner in = new TestClass().new Inner();
System.out.println(in instanceof TestClass.Inner); //instanceof has no relation to the outer TestClass instance.
}
}
-
- Posts: 2
- Joined: Wed Aug 20, 2014 8:43 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1521 :
Is next statement true: Non-static inner class cannot have static members.
Inner classes can always have final static fields with a value, which is a constant and a member! So the above option is never true. Without a value it is not allowed in a non-static inner class and then it is Ok.
Inner classes can always have final static fields with a value, which is a constant and a member! So the above option is never true. Without a value it is not allowed in a non-static inner class and then it is Ok.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1521 :
No, the statement is not true.
-
- Posts: 22
- Joined: Mon Jul 06, 2015 11:45 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1521 :
hi guys.
i dont understand following.
- Anonymous classes cannot be static
why ? for example, isn't it right static anonymous class?
class MyClass {
static Runnable runnable1 = new Runnable() {
@Override
public void run() {
}
};
}
Thanks in advance
i dont understand following.
- Anonymous classes cannot be static
why ? for example, isn't it right static anonymous class?
class MyClass {
static Runnable runnable1 = new Runnable() {
@Override
public void run() {
}
};
}
Thanks in advance
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1521 :
No, it is not. The variable runnable1 is static, not the anonymous class.
Who is online
Users browsing this forum: No registered users and 4 guests