Divakar

Greenhorn
+ Follow
since Mar 01, 2000
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Divakar

Almost clear.
One more qn:
All the classes in java are automatically subclass of Object.
Same way does all the interfaces inherit Object??
This qn is from mock exam at http://www.geocities.com/SiliconValley/Screen/5046/

public class Base extends Object implements Runnable{
public static void main(String argv[])
{
Base t=new Base();
Derived d=new Derived();

Object o= t;
Runnable rn=(Runnable)o;//******

}
public void run()
{
}

}
class Derived extends Base{



}
Why line marked **** doesn't throw Exception???
We are assigning child interface object ref to parent class.
If it is class instead of interface
say
d=(Derived)o;

it will throw exception at runtime.
For interfaces will it work differently??

Can anybody explain what happens in shift operation when we use a negative number
eg
3>>-1
public class q
{
public static void main (String argv[])
{
boolean x=true;
boolean y=true;
System.out.println(x=~y);
}
}
The expected output is false.
But this one is giving compile time error why??
This is great Joe.
Thanks a lot.

Rgds
Divakar
True or false
JVM will not throw any exceptions. Only programs will throw exceptions.

Congrats Joe,
In java.io what and all we have to study?? How was your preparation in io and awt.
Thanx in advance
Divakar

I got where I went wrong. Actually first code was as the following .
import java.io.*;
class Base{
public void amethod()throws IOException{}
}
public class ExcepDemo extends Base{
public static void main(String argv[]){
ExcepDemo e = new ExcepDemo();
}
public void amethod(){}
ExcepDemo(){
try{
DataOutputStream ds = new DataOutputStream(new FileOutputStream(new File("a.txt")));
ds.writeChar('a');
this.amethod();
}catch(IOException ioe) {}
}
}
While copying from the mock test I missed the DataOutputStream line. (also the import java.io.*; line).
This one wont'give error because DataOutputStream line may throw IOException.
See the following code.

public class ThreadTest
{
public static void main(String argv[])
{
child1 c1=new child1();
child2 c2=new child2();

c1.start();
c2.start();
System.out.println("main");

}
}
class child1 extends Thread
{
public void run()
{
System.out.println("Child1");
}
}
class child2 extends Thread
{
public void run()
{
System.out.println("Child2");
}
}

This code prints
main
Child1
Child2
Why it is printing like this
Child1
Child2
main
is the correct order right??
When I am calling c1.start() it will call run method of the Child1 . This will print Child1.Similarly for Child 2. After this it will print main.
Don't know what is happening??
Please help.

What is the difference between int[] a; and int a[];
a)No difference.
b)First one will give compilation error.
c)Second one will give compilation error.
d)First one represents array of int references.
e)Second one represents array of int references.
f)both represents array of int elements.
What is the answer??
My answers- a,d,e
Again carelesness .I didn't notice "member variable" . So gone ahead with objects.
This code compiles and while running error thrown at try block is caught by catch.
All the confusion arised from the Sun java documentation for Errors.
They have given
"An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it. "

Which of the following statements are true?





a) Overridden methods have the same method name and signature

b) Overloaded methods have the same method name and signature

c) Overridden methods have the same method name and different signature

d) Overloaded methods have the same method name and different signature
My answers (a) and (d).
Can overloaded methods have same signatures??
Signature of overloaded method will include its name argument type and not its return type.Overloaded method means same method name and differrent arguments. If you change the argument the signature will also change ,am I right??
This is a question from IBM exam.
With respect to Exceptions, RuntimeExceptions and Errors:

a) All may be caught using try {...} catch () {...} syntax.

b) Developers cannot create their own Error subclasses.

c) A RuntimeException must always be caught or declared as thrown by the method which raises it.

d) Non-RuntimeExceptions must always be caught or declared as thrown by the method which raises them.

e) Errors must always be caught or declared as thrown by the method which raises them.

My answer is (d)
Can Errors be caught using try catch block??