Page 1 of 1

About Question enthuware.ocpjp.v7.2.1521 :

Posted: Sun Jun 23, 2013 8:25 am
by The_Nick
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.

Re: About Question enthuware.ocpjp.v7.2.1521 :

Posted: Sun Jun 23, 2013 11:16 am
by admin

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.
  }
}

Re: About Question enthuware.ocpjp.v7.2.1521 :

Posted: Thu Nov 13, 2014 4:42 am
by Huib valstar
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.

Re: About Question enthuware.ocpjp.v7.2.1521 :

Posted: Thu Nov 13, 2014 8:22 pm
by admin
No, the statement is not true.

Re: About Question enthuware.ocpjp.v7.2.1521 :

Posted: Mon Jul 06, 2015 11:52 am
by fariz.siracli
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

Re: About Question enthuware.ocpjp.v7.2.1521 :

Posted: Mon Jul 06, 2015 11:55 am
by admin
No, it is not. The variable runnable1 is static, not the anonymous class.