Lavanya Raguram

Greenhorn
+ Follow
since Apr 03, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Lavanya Raguram

so is that there is no specific reason, why multiple inheritance was allowed in interfaces but it is not so in classes?
18 years ago
then y is that multiple inheritance is allowed thro interface when it is not the case in a class???
18 years ago
java does not support multiple inheritance of classes to prevent inheritance of a same method or a variable twice or more and to prevent any discrepancy regarding it but however it supports the same through interface and will not the same discrepancy creep in here?
pls explain
18 years ago
still i am confused :roll:

consider if it is main=>method1=>method2=>method3(throws exception)

now consider method3 handles it using try\catch block so should method2 declare or handle it.
also should method1 declare or handle it.
Pg no 634 on K&B book

public static <E extends Number> List<? super E> process<List<E> nums>

now the method to be used is
//declaration
output=process(input);

which declaration could be placed?

a)ArrayList<Integer> input=null;
ArrayList<Integer> output=null;
b)ArrayList<Integer> input=null;
List<Integer> output=null;
c)ArrayList<Integer> input=null;
List<Number> output=null;
d)List<Number> input=null;
ArrayList<Integer> output=null;
e)List<Number> input=null;
List<Number> output=null;
f)List<Integer> input=null;
List<Integer> output=null;

the ans is b,e anf f.Pls explain
now if method2 handles the exception by a try/catch block then should method1 or main or both declare or handle the exception ?
consider if a method throws a checked exception and it is enclosed inside another method which is called from main function.

so now should all the functions either handle or declare the exception.

pls explain...
K&B book (pg no 267) ques no :3

class a{
String inv(short s){return "inv";}
String inv(short... s){return "var arg";}
}
class b
{
public static void main(String args[])
{
System.out.println(new a().inv(7)); //compilation fails
}
}

the ans is:compilation fails since there is no explicit cast
during a noraml assignment short s=7; succeeds but y does it fail wen it is passed as an argument
wat will be the answer for this question? pls explain

public class SyncTest {
private int x;
private int y;
private synchronized void setX( int i ) { x = i; }
private synchronized void setY( int i ) { y = i; }
public void setXY( int i ) { setX(i); setY(i); }
public synchronized boolean check() { return x != y; }
}

Under which condition will check return true when called from a different class?
A. check can never return true.
B. check can return true when setXY is called by multiple threads.
C. check can return true when multiple threads call setX and setY separately.
D. check can return true only if SyncTest is changed to allow x and y to be set
separately.
pls explain the answer for this question too

Thread Z holds the lock on object A. Thread X is blocked inside a wait call on ObjectA.
What allows thread X to become runnable?
A. Thread X is interrupted.
B. Thread X is interrupted.
C. Thread X�s wait() times out.
D. Thread Z calls Thread.sleep(100);
E. Thread Z releases the lock on A and calls the notify() method on thread X.
F. Thread Z releases the lock on A and calls the notifyAll() method on objectA.
wat will be the answer for this question? pls explain

public class SyncTest {
private int x;
private int y;
private synchronized void setX( int i ) { x = i; }
private synchronized void setY( int i ) { y = i; }
public void setXY( int i ) { setX(i); setY(i); }
public synchronized boolean check() { return x != y; }
}

Under which condition will check return true when called from a different class?
A. check can never return true.
B. check can return true when setXY is called by multiple threads.
C. check can return true when multiple threads call setX and setY separately.
D. check can return true only if SyncTest is changed to allow x and y to be set
separately.
ya sorry actually i missed those braces

so do u mean that for overriding a method with exception declaration we should either enclose the overriding method in a try catch block or declare those exceptions in the overriding method too ?
i have a doubt in this program(K&B pg 104)

class animal
{
public void eat() throws Exception
{}
}
class dog extends animal
{
public void eat(){}
public static void main(String args[])
{
animal a=new dog();
dog d=new dog();
a.eat; //compiler error
d.eat; //ok
}

why is it so?
its not necessary that a overriding method should throw the exception specified in a overriden method right?
which of following correctly describes how variablers are passed to methods?

a)Arguments are always passed by value
b)Arguments are always passed by reference
c)Arguments that are primitive types are passed by value
d)Arguments that are passed with & operator are passed by reference

Pls explain
but is it enough to go thro K&B book alone n rely on their mock exams ?
does any other book help in this regard?