Page 1 of 1

About Question enthuware.ocpjp.v7.2.1484 :

Posted: Thu Mar 06, 2014 10:27 am
by erbegu

Code: Select all

abstract class SomeClass {   public abstract void m1(); }
public class TestClass
{
  public static class StaticInnetClass { }  //option 1
  public SomeClass getSomeClass()
  {
      return new SomeClass()
         {
            public void m1() { }
         };
  }
}
Is this the way meant for extending from SomeClass? Without using "extends" anywhere?

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

Posted: Thu Mar 06, 2014 10:57 am
by admin
Yes, it is correct. It shows you various valid scenarios mentioned in the options.

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

Posted: Thu Mar 06, 2014 3:21 pm
by erbegu
Thank you!

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

Posted: Wed Oct 15, 2014 6:47 am
by vijayanand
Is this the only way a class can extend an abstract class without using extend keyword?

if there is any other way, please suggest

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

Posted: Wed Oct 15, 2014 10:58 am
by admin
Yes, that is the only way.

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

Posted: Thu Apr 06, 2017 1:54 pm
by insider
Typo in "StaticInnetClass". Probably, should be "StaticInnerClass".

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

Posted: Sun Sep 11, 2022 12:19 pm
by sohamdatey22
Anonymous inner classes can also be, instance members, and declared outside the method in class.
The question should denote that, which anonymous inner class we are referring here.

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

Posted: Mon Sep 12, 2022 11:39 am
by admin
Not sure which option are you referring to here and what is your issue with that option. Can you please provide more information about what you are trying to convey?

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

Posted: Fri Dec 02, 2022 7:43 am
by felipewind
Can you please confirm that I really can't add access modifiers to the anonymous inner class?

Is this a valid example of an private anonymous inner class ("Anonymous inner class may be declared private."):

Code: Select all

public class Hi {   
	private static Function<String, Integer> F = new Function<String, Integer>() {
		public Integer apply(String s) {
			return Integer.valueOf(s);
		}
	};
}
Thanks

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

Posted: Fri Dec 02, 2022 9:14 am
by admin
No, your example shows the keyword private being applied to the variable F and not to the anonymous inner class.

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

Posted: Fri Dec 02, 2022 10:13 am
by felipewind
admin wrote:
Fri Dec 02, 2022 9:14 am
No, your example shows the keyword private being applied to the variable F and not to the anonymous inner class.
Yes, thanks for clarifying this for me.