About Question enthuware.ocpjp.i.v11.2.1469 :

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

Moderator: admin

Post Reply
webber
Posts: 18
Joined: Mon Apr 01, 2013 8:38 am
Contact:

About Question enthuware.ocpjp.i.v11.2.1469 :

Post by webber »

As written I did not managed to answer to this question.

I think :

1- the filterData should be declared static or a Data Object should be instantied.

2- the al Arraylist should be instantied too.



I rewrote the code like this:

Code: Select all

static void filterData(ArrayList<Data> dataList, Predicate<Data> p){

       Iterator<Data> i = dataList.iterator();
        
       while (i.hasNext()){
       
            if (p.test(i.next())){
                 i.remove();
            }
       }
}

...........

ArrayList<Data> al = new ArrayList<>();
        
Data d;
        
d = new Data(1);    al.add(d);
d = new Data(2);    al.add(d);
d = new Data(3);    al.add(d);
        
//INSERT METHOD CALL HERE

System.out.println(al);

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

Re: About Question enthuware.ocpjp.i.v11.2.1469 :

Post by admin »

As the problem statement says, these are just code fragments. Not complete code listings. You need to assume that they are present within valid context where they will compile and run.

No, filterData need not be static. The given code fragment could also be a part of some other instance method:

Code: Select all

class Test{

    void filterData(...){ ... }

    void someOtherMethod(){
        ArrayList<Data> al = new ArrayList<Data>();  //not shown in the given code, assume that it exists


        Data d = new Data(1); al.add(d);
        d = new Data(2); al.add(d);
        d = new Data(3); al.add(d);

        //INSERT METHOD CALL HERE
       System.out.println(al);
    }
}

webber
Posts: 18
Joined: Mon Apr 01, 2013 8:38 am
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.1469 :

Post by webber »

Ok, Thanks.

But, in this case, propositions shouldn't be marked :

d.filterData(al, d -> d.value%2 == 0 );
d.filterData(al, (Data x) -> x.value%2 == 0 );
...
instead of simply
filterData(al, d -> d.value%2 == 0 );
filterData(al, (Data x) -> x.value%2 == 0 );
...

otherwise filterData method seems to be declared static ?

comparing with the other questions this seems very ambiguous.

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

Re: About Question enthuware.ocpjp.i.v11.2.1469 :

Post by admin »

webber wrote:
Wed Jun 24, 2020 5:21 am
Ok, Thanks.

But, in this case, propositions shouldn't be marked :

d.filterData(al, d -> d.value%2 == 0 );
d.filterData(al, (Data x) -> x.value%2 == 0 );
...
instead of simply
filterData(al, d -> d.value%2 == 0 );
filterData(al, (Data x) -> x.value%2 == 0 );
...

otherwise filterData method seems to be declared static ?

comparing with the other questions this seems very ambiguous.
No, you don't need to do d.filterData because someOtherMethod and filterData methods are instance methods of the same class Test in the code that I showed above. Implicit variable this will be used.
I understand that you feel it is weird but you will see partial code fragments in the exam also. You should assume that they are placed in valid context.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests