Himai Minh wrote:In the previous example, it prints out tree elm elm elm from the go method.
The first one outputs tree from the invocation t.getTree().
Since t is a tree, it calls getTree and getTree calls getmyOwnTree.
The most interesting invocation is new Elm().getTree().
The Elm instances inherits getTree. This getTree calls getmyOwnTree of Elm's version.
In the Elm's getmyOwnTree, the "return tree" returns the Elm's tree.
Why getmyOwnTree in Elm choose "elm" to return instead of "tree" ?
It is because Elm's getmyOwnTree overrides its parent's method. That means Elm behaves differently than its parent.
Let's go back to the original example:
When Elm instance calls getTree(), it reuses its parent's getTree method. So, this Elm instance should behaves in the same way as its parent. Therefore, it returns "tree" instead of "elm".
Summary: a child inherits a method meaning that this child behaves in the same way as its parent. A child overrides a method meaning that this child behaves differently than its parents.
Mahtab Alam wrote:Well congrats >
Is 2:30 time was enough.And what was the level of questions .
I have my exam on 16 saturday
Mahtab Alam wrote:many says that you will have 15-20 easy question on the ocjp test.
how much true is it.
and will there be drag and drop questions , and does you have to create them from starting while reviewing.
so its better to write them on the paper.
Mahtab Alam wrote:Which are most commonly thrown by an API developer or application developer as opposed to be thrown by JVM
Answers are:
IllegalArgumentException
IllegalStateException
NumberFormatException
I can`t understand what it means to be thrown by API developer
Mahtab Alam wrote:many says that you will have 15-20 easy question on the ocjp test.
how much true is it.
and will there be drag and drop questions , and does you have to create them from starting while reviewing.
so its better to write them on the paper.
Jesper de Jong wrote:You can ofcourse find that information on Oracle's website: Exam 1Z0-851: Java SE 6 Programmer Certified Professional
Henry Wong wrote:Please QuoteYourSources
Greg Charles wrote:Yes, if you tell it that one comma is the delimiter, it will take you at your word and return empty strings for two commas in row. That's a good thing. Let's say you had the data:
"FirstName,Nickname,LastName"
"Ralph,'Macho',Camacho"
"Greg,'T-bone',Charles"
"Rachel,,Glenn"
You'd want your first and last names parsed out correctly even though you don't have a nickname.
If you really want to split the string on one or more commas, you just need to change the regular expression in the split() to string.split(",+"). In that case, the first three strings above get split into three pieces, but the last one only gets split into two.
Greg Charles wrote:It's confusing because it's weird to think of digits as delimiters. Imagine the string was "x,,,, y,, z, a" and you split it on the commas. You'd expect to get eight strings returned, many of which would be empty because there are multiple commas in a row with nothing between them.
Zhenyi Luo wrote:
Rachel Glenn wrote:I have this sample question from a mock exam:
Given:
- list is a reference to a valid collection
- getCollection() returns a reference to a valid collection
Which two are valid? (Choose two.)
A. for(Object o ; list)
B. for(Object o : list.iterator())
C. for(Object o : getCollection())
D. for(Iterator i ; list.iterator() ; i.hasNext() )
E. for(Iterator i = list.iterator(); i.hasNext(); )
I understand that answer E is one of the correct options. But it seems to me that options A AND C are also valid. Can someone please explain? (Option C is the other correct option.)
A should be for(Object o : list) instead of for(Object o ; list) , so answer is CE
Zhenyi Luo wrote:
Rachel Glenn wrote:UGH, another ambiguous question..this is from a mock exam
Given:
21. class Wheels {
22. private Bike bike;
23. void setBike(Bike b) { bike = b; }
24. }
25.
26. class Bike {
27. private Wheels [] wheels = new Wheels[5];
28. void setWheels(Wheels [] w) {
29. if( w.length == 2)
30. wheels = w;
31. }
32. }
Which is true?
A. Compilation fails.
B. These classes are NOT coupled.
C. These classes are loosely coupled.
D. These classes are tightly coupled.
E. These classes are abstractly coupled.
(Option D is correct because both classes have references to instances of each other.)
Why is this considered tight coupling? Internal changes to either Wheels or Bike classes do not affect the other class. What would make these considered as being loosely coupled?
Internal changes to either Wheels or Bike classes will affect the other class, setBike is in Wheels class and setWheels is in Bike class.