Q1. Which of the following will add a Component 'comp' to a container 'c', if it's layout is governed by GridLayout 'g'? Select all 3 correct choices: 1.c.add(comp); 2.c.add("Center",comp); 3.g.add(comp); 4.g.addLayoutComponent("CompName",comp); 5.c.add(comp,-1); I checked 1,2,5(even 2. .They gave correct answers as 1,4,5. Please an explanation. Q2.Which of the following statements about hashCode() method of Object class are true? Select all 2 correct choices: 1.is a native method; 2.it return int; 3.it return long; 4.it cannot be overriden; 5.none of the above. To me only 2 seem correct answer. API states ublic int hashCode(); if I run javap java.lang.Object the definition is public native int hashCode().For the exam purpose should I know this? Please confirm.
For the second question, it is int and native. The API doesn't tell you when it is native because it shouldn't matter to the programmer whether it is native or not. As for whether or not you need to know this, well it is part of the objectives, so yes they could ask you something like this. I don't know if they will get that detailed as to wanting to know if a method is native or not, but that is why mocks help so much. Things you wouldn't read or pick up, can be brought to light. Bill
for the first, ichecked 1 and 4. about addLayoutComponent : addLayoutComponent public void addLayoutComponent(String name, Component comp) Adds the specified component with the specified name to thelayout. Specified by: addLayoutComponent in interface LayoutManager Parameters: name - the name of the component. comp - the component to be added.
Hi, For question 1, number 5 is also correct. The Container class supports two add methods: add( Component comp); add( Component comp, int index ); Index in the second one is the position of the new component. The value of -1 places the comp at the end (the default!). So number 5 is exactly the same as 1! Regards, Manfred.
Joined: Dec 25, 2000
definetly 1,5 are correct and i say 2 works fine also
so,why choice 2 is not a valid answer?
Joined: Jan 09, 2001
Hi Cristi, I think 2 is not shown as a valid answer to the question because it shows bad Java programming. Usually the literal Strings: "North", "South", "West", "East", and "Center" are used when adding components into a BorderLayout. I am not saying it won't work. In your example, the literals are being accepted as component names. I also don't think that the real exam would have any such ambiguity! Regards, Manfred.