About Question enthuware.ocpjp.v7.2.1310 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
jaypi
Posts: 8
Joined: Sun Feb 03, 2013 9:47 am
Contact:

About Question enthuware.ocpjp.v7.2.1310 :

Post by jaypi »

This is a valid (yet refused) answer:

Code: Select all

public class TestClass {

	public static void main(String[] args) {
		Set<String> holder = new TreeSet<>();
		holder.add("tom");
		holder.add("dick");
		holder.add("harry");
		holder.add("tom");
		printIt(holder);
	}

	public static void printIt(Collection<String> list) {
		for (String s: list) System.out.println(s);
	}

}

admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Yes, it is valid but you need to fill all the yellow drag targets. So you need to put TreeSet<String> instead of TreeSet<>.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

bluster
Posts: 60
Joined: Wed Apr 23, 2014 6:38 pm
Contact:

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

Post by bluster »

My compiler was happy with this (rebuffed) one, producing the expected output.

Code: Select all

public class TestClass {

   public static void main(String[] args) {
      Set<String> holder = new TreeSet<String>();
      holder.add("tom");
      holder.add("dick");
      holder.add("harry");
      holder.add("tom");
      printIt(holder);
   }

   public static void printIt(Collection<String> list) {
      for (String s: list) System.out.println(s);
   }

}
Also, the solution filled all the yellow drag targets. Thirdly, the explanation goes with
can be Collection<String> or any subclass of Collection<String> such as Set<String>.


Can someone tell me what condition was not fulfilled to have the answer considered OK? Thanks!

admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

I tried the same and it was evaluated as correct. May be you had a typo in TreeSet?
-Paul.
If you like our products and services, please help us by posting your review here.

bluster
Posts: 60
Joined: Wed Apr 23, 2014 6:38 pm
Contact:

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

Post by bluster »

It could have been that. Thanks for checking!

AndaRO
Posts: 31
Joined: Wed Feb 08, 2017 5:42 pm
Contact:

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

Post by AndaRO »

I can't drag 'Set' keyword.

admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

I tried it just now. Seems to be working fine. Try taking it close to the yellow target and it should go there.
-Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 109 guests