About Question enthuware.ocajp.i.v8.2.1399 :

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

Moderator: admin

Post Reply
chmelvv
Posts: 3
Joined: Fri Nov 22, 2013 4:58 am
Contact:

About Question enthuware.ocajp.i.v8.2.1399 :

Post by chmelvv »

Code: Select all

import java.util.*;
public class ClassnameTest {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        StringBuilder sb = new StringBuilder("mrx");
        String s = sb.toString();
        list.add(s);
        System.out.println(s.getClass());
        System.out.println(list.getClass());
    }
}
========= Console output:
class java.lang.String
class java.util.ArrayList

Process finished with exit code 0
==========
So Explanation correct, but answer in test - NOT.
"The getClass method always returns the Class object for the actual object on which the method is called irrespective of the type of the reference."
Last edited by admin on Tue Apr 12, 2016 9:37 am, edited 2 times in total.
Reason: Please put code within [code] [/code]

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

Re: About Question enthuware.ocajp.i.v8.2.1399 :

Post by admin »

Why do you think the answer is incorrect? How does the output that you've shown prove otherwise?
-Paul.

chmelvv
Posts: 3
Joined: Fri Nov 22, 2013 4:58 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1399 :

Post by chmelvv »

Because as the right answer exam system proposes:
class java.lang.String
class java.util.List


What output proves? Compiler output is truth in the last instance.

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

Re: About Question enthuware.ocajp.i.v8.2.1399 :

Post by admin »

I see that option 3 is marked correct and it says:

class java.lang.String
class java.util.ArrayList

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests