srikrish

Ranch Hand
+ Follow
since Sep 12, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by srikrish

The compiler is behaving as it should since the first return statement is inside a try block. If you remove the try statement and the catch block, so that both the return statements occur under the same block, then you get an error message at the second return statement since it is unreachable. So, the critical factor here is to note if the two return statements occur within the same block.
hope this helps.
Srikrish
I'd like to correct what Anna has mentioned for objects. Both primitive types as well as object references are passed by value (i.e., a copy of the value is sent to the called method). The speciality in case of objects is that the value that is copied is nothing but the reference (memory address) of the object. So, the called method is also pointing to the same object as the calling method. So, whatever changes that the called method makes to the object affects the calling method too.
Hope this is clear.
Srikrish.

[This message has been edited by srikrish (edited October 14, 2000).]
Congrats! Great job!!
Srikrish.
Congrats Dilip! Great score!!
Srikrish
Pragya,
About the materials that I used...
RHE was a goos way to start. I also referred to Core Java Vol II by Cay Horstmann and Gary Cornell. It's got good explanations for Threads and Collection, List, Set, etc. All my other study materials involved dwelling on this site for hours together and going thru' all the discussions, past and present. I got to know a lot of intricate points this way which really helped during the exam.
About tips...
Try writing as much code as possible to try out different possibilities and learn from the results. Take all the mock exams mentioned in Maha Anna's page here. Draw up a table of the different types of streams and readers with their use, constructors and read methods. This really helped me in understanding the different streams and readers. Get to know the API specs for important classes well.
One final tip..never lose heart. Keep trying!
Good luck for your exam.
Srikrish.

[This message has been edited by srikrish (edited September 18, 2000).]
[This message has been edited by srikrish (edited September 18, 2000).]
Hi folks,
I want to let you know that I cleared my SCJP exam today with 92%! I can't emphasize how vital this forum was for me in my preperations and the role it played in my exam itself! Although I knew Java concepts, my preperation for the exam was only for 10 days and I thrived on this site for help.
A BIG THANK YOU to all the folks who post their questions here and to those who provide those wonderful explanations to them! It really, really helped!! HAving gone through the exam questions, I can't help feeling tthat I could have done better. But 92% for a 10 day preperation is fine with me and I'll take it any time of the day!!
To those who are preparing for the exams with the help of this site, I have just one word. YOU ARE ON THE RIGHT TRACK!!
I promise to visit this site as often as I can and provide my inputs, learning from you all at the same time.
Loads of gratitude,
Srikrish
Sherin,
You can declare an array in the []variable[] format. But you cannot create an array using that format.
i.e., int []a[]=new int[4][4]; is correct
but int []a[]=new [4]int[4]; is wrong.
Hope this helps.
Srikrish
Michael,
Inner classes can be either static or non-static. The option B says that Inner classes MAY be static which is true.
Srikrish
Laura,
Since it is said that it a 8-bit file (byte), I don't think you can use the FileReader (FileReader is used for reading 16-bit character files). We need to use the FileInputStream instead which can 8-bit files. So, the code might be rewritten to say something like this:

InputStreamReader is the bridge which converts the bytes returned by the FileInputStream into characters that are fed into the BufferedReader.
Hope this helps.
Could anyone please correct me if I'm wrong?
Srikrish
ok, this is going to be big reply.....
Q1:When you call static methods with object references (bc.sayHello()), it goes by the type of the variable and not the type of the actual object itself. In other words, bc.sayHello() is equivalent to BaseClass.sayHello(). Since, bc is of type BaseClass, the sayHello method of BaseClass was executed. If the sayHello method was not static, then the SubClass's sayHello method would have been executed because of polymorphism.
Q2: The given answer is right. I think you are confused with super() of constructor and super.normalmethod(). The restriction that you talk about (being the first statement) applies only to a super() call to the CONSTRUCTOR of a base class. Here, aMethod() is not a constuctor. It is a normal method. And the super.aMthod() statement can be anywhere in the aMethod() of subClass.
Q3: When you declare explicit constructors for a class, then you need to define the default constructor too explicitly. Here, the BaseClass does not have a default constructor. So, when the SubClass object is created (and since there is no explicit calls to any of the BaseClass's declared constructors), it will place a call to BaseClass() (default) constructor of the BaseClass. Since it doesn't find it, it will give a compile error.
Q4: Once a method throws an Exception, the control gets out of the method. So, the i-- statement is never executed here. And the compiler objects to such unreachable code.
Also, IOException can be thrown since it implements the Throwable interface.
Q5: These are the objects that are created by this code:
1. "Hello"
2. "Pal"
3. "HelloPal" (coz of s2+"Pal")
s1 and s2 both point to the "Hello" object. s3 and s4 both point to the "HelloPal" object.
Hope the explanations are clear.
Srikrish
One more reason why the Listener implementation is incorrect is that the actionPerformed method is declared with package level access in this code. The compiler will object to this since the actionPerformed method is declared as a public method in the ActionListener interface and you cannot override it to be more private.
The above code generates a compile error if the value assigned to the byte variable b made to be a negative number. So, I guess the compiler goes by the value that is stored in the byte variable before it decides whether it is an error or not.
I agree with snigs about answer a. When you create a thread objet using Thread t1=new Thread() and Thread t2=new Thread(t1), the code compiles and runs fine.
I also share Dilip's concern regarding the instanceof operator. I would expect it to return false but not give a compile error. The error message talks about incompatible types. Could someone explain on this please?
Shi,
There is no problem with String having a replace() method. Infact, String can have any kind of method which modify the string (if so required). The only point to note in all these methods is that they produce new objects as their output (there are exceptions - refer the API for that). For StringBuffer, the update methods do not produce a new object. That is the only difference.
The summarization is good.
Just a correction. Point #5 under GridLayout. It does not produce compile error but produes an IllegalArgumentException (RunTimeException).