Anushkha Rana

+ Follow
since Apr 13, 2003
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Anushkha Rana

Hi all,
Though late, still thanx for replying and helping me out. Somehow, i don't get the mails for my postings.
Thanx again

posted by Thomas Paul
How could this compile if Dog didn't inherit fur?
class Fur {}class Pet { Fur fur = new Fur(); }public class Dog extends Pet {Fur a = fur;}

I think this code will get compiled not because of Fur is being inherited by Dog but because class Fur is being defined in the same file as class Dog. And having package accessiblity, all the classes within this package can access class Fur.
if Fur is inherited by Dog then this should compile..

*i guess*, i am not making any mistake.
Hi Charles!

What is the code for Base class? Without it we cannot judge Base() is correct or not.

We don't need Base class code to decide this. Think about it this way.
Base class will have a non argument constructor because of line numbered 5. Right??
This implies that compiler will not provide implicit default constructor when reqd. One has to explicitly provide it.
Now, what will the constructor Test(int j) call when it does not have an explicit call to base class constructor?? Definitely! default constructor. So,compiler will complain if we don't provide Base class' default constructor explicitly.
Hope, i made myself clear.
What is the method used to schedule a thread for execution?
Answer given is run()
I think correct answer should be start().
What is true about threads that stop executing?
A.When a running thread's suspend() method is called, then it is indefinitely possible for the thread to start.
B.The interpreter stops when the main method stops.
C.A thread can stop executing when another thread is in a runnable state.
Can somebody help me get the meaning of option A.
And correct answer to this question.

Does it mean that static method are initialized before static variables?

Charles, methods never get initialized.
It is the memeber variables that are intialized using initializer expressions and initializer blocks. Approriate method simply get invoked when there is a call for it in an initializer expressions or initializer blocks.
Static initializer expressions and static initializer blocks get executed only once when the class is loaded, in the order they appear in the class.
Instance initializer expressions and instance initializer blocks get executed every time a new instance is created, in the order they appear in the class.
Hi All!
This I think should be the answers:
Quiz #4
compiler will complain at line B b = this; because base class reference cannot be assigned to derived class reference without explicit casting. At compile time, keyword this within method m() denotes object of class A.
if its changed to B b = (B)this; then output should be:
Quiz #5
output should be:
Quiz #6
output should be:
and ClassCastException at C c = (C)this; because base class object cannot be denoted by derived class reference.
Right, Marlene??
[ April 15, 2003: Message edited by: Anushkha Rana ]
Its really confusing!!
Kathy says in one of the threads

a NON-static inner/nested class could be called any of the following:
* nested class
* inner class
* method-local inner class
* anonymous inner class

However, BruceEckel in TIJ (Topic: Nested classes) says

If you don�t need a connection between the inner class object and the outer class object, then you can make the inner class static. This is commonly called a nested class.

He uses Inner classes the same way as u said:

Inner classes include non-static member classes, local classes and anonymous classes.

The answer should be:
Please correct me if i am wrong.

For instance, you could interpret the Set method contains that returns true or false depending on if an object is a memeber as a lookup method.

Well! Set interface do have such a method contains(). Isn't it??
from API doc

public boolean contains(Object o)
Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)).

Thanx guys for the response..
I hope there is no confusion regarding this terminology in the exam

posted by Martin Smith
I think only C is correct.

Well! Both C and E should be correct as Roger explained:

posted by Roger Chung-Wee
If a thrown exception is not caught and handled, then it must be declared. The declaration can be the exception or any of its superclasses. These are all valid:
public void method() throws IOException
public void method() throws Exception
public void method() throws Throwable
We are assuming that was imported.
So, E is correct.

Thanx! Roger for the feedback.
It helps!
Given the following incomplete method.
1. public void method(){
3. if (someTestFails()){
5. }
You want to make this method throw an IOException if, and only if, the method someTestFails() returns a value of true. Which changes achieve this?
A.Add at line 2: IOException e;
B.Add at line 4: throw e;
C.Add at line 4: throw new IOException();
D.Add at line 6: throw new IOException();
E.Modify the method declaration to indicate that an object of [type] Exception might be thrown.
Answer given is (D), (E).
According to me answer should be (C) & (E).
(E) only if method being referred to is method(), not someTestFails(). Am i right??

Here is a strange thing that i am unable to understand. I tried the following code(though it may appear similar but it has nothing to do with the above question):

output is:
Inside catch block of func2()
Inside func1()
InterruptedException (at line 1) thrown inside catch block of func2 is not being propogated to default exception handler. However if the throws clause from header of main() and func1() is removed, compiler complains.
On the other hand if line 1 and line 2 are interchanged (i.e. instead of throwing exception at line 1, true value is returned and instead of returning a boolean value at line 2, exception is thrown), exception is being propagated to defalut exception handler as expected.
Output is:
Inside catch block of func2()
Exception in thread "main" java.lang.InterruptedException: InterruptedException in catch block of func2()
at Qs.functionfailed(
at Qs.withinsomefunc(
at Qs.main(
Can anybody expalin me why is this happening?
Can somebody explain me the naming coventions related to Nested Classes?
Some questions are specific when mentioning whether they are refering to static inner classes or non static inner classes or local classes or anonymous classes. But sometimes the questions simply refer as inner class (which is synonymous to non static inner classes - please correct me if i am wrong). Which one is being referred to in such a case?
Am i right to say that static inner class is also called nested class?
Thanx in advance!!

posted by Jose
I think there are six String objects created.
--new String("Nick")-- will create a string object holding the word Nick and will intern it. Then that object is passed to the constructor of String that takes another String. The constructor creates another string, but this time it wil not intern it. Thus there are two string objects created.

Well! i don't understand how 6 objects are created. How can we monitor whether a string literal or constant expressions is being interned?