I have been preparing for the OCPJP exam for the past 3 months. I have scheduled my exam (its within one week from now) but I am really worried I have followed SCJP Preparation book by K&B and I believe I understood the basic concepts underlined in the book.
I am taking the simulated exams from ExamLab and the score is really poor I have also followed the OCP Exam Preparation and there as well the score is just the same 50% only
My weaknes is that I forget things too quickly... I can understand them well ... write programs with no problem.... I have practiced mainly on IDE... I have recently started practicising several programs without the help of IDE and there seem to be several exceptions and errors that I encountered and understood during that time.
Especially on the formatting and exceptions, I get confused when its time to decide between compile time error or run time exception
But thankyou all, I will refer to the appropriate forum
posted 7 years ago
It is probably not a good idea to practise on IDEs; they are intended for rapid development, not for learning. It is only practice that will enable you to remember things.
I don’t understand what you said about exceptions and compile-time errors.
Kaur Manpreet wrote:I had a tough time understanding the ClassCastException thrown at runtime and inconvertible types compile time error.
Well, it is not much difficult to identify if you understand inheritance hierarchy.
Inconvertible compile time error occurs when compiler knows for sure that type of the references are not convertible at all. ClassCastException occurs when casting of references is possible, but at runtime, actual objects are not convertible.
This happens because, at line 7, compiler knows that d is a reference of type Dog, and there's no way that it can refer to a Cat object, so, at compile time itself, there is an inconvertible type error.
But at line 9, animal is a reference of type Animal, and there is a chance that it can refer to either Animal, Cat or Dog object. So, compiler doesn't complain about this casting. But at runtime, animal is actually referring to a Cat object, which cannot be converted to Dog object(or, to be specific, a reference of type Dog cannot refer to Cat object), and hence, there is a ClassCastException.