GM Shobha

+ Follow
since Apr 22, 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 GM Shobha

The code gives NullPointerException and not the compiler error. As the array is 2-dimensional array & 2nd dimension is not defined,we cannot access the element a1[1][0].
Hi Nadeem,
Sometime back, question below was discussed in this forum.
public static void main(String args [])
for(int i=10;i>0;i--){
String s =new String(�Hello�);
System.out.println(�world�); // 9
How many objects eligible for GC at line no 9 ? & the answer given was 10.
Pl verify how is this problem different from the above.
class Q {
private int id;
public void finalize() {System.out.print(id);}
public Q(int i) {id = i;}
class R {
public static void main(String[] args) {
Q q1 = null;
for (int i = 0; i < 10; i++) {
q1 = new Q(i); // 1
System.gc(); // 2

When the processing of line 2 begins how many objects of type Q that were created at line 1 are eligible for garbage collection?
Answer 10 or 9??
Please explain,why is this condition return true?
The value of v.i is reset to 20.However again v(object) is made to refer to object vh & value of i in vh is 10.
class ValHold{
public int i = 10;
public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
public void amethod(){
int i = 99;
ValHold v = new ValHold();
System.out.print( v.i );
//output is 20 instead of 10??
}//End of amethod
public void another(ValHold v, int i){
v.i = 20;
ValHold vh = new ValHold();

v = vh;//instead of this statement if it is v.i=vh.i; output is 10010
}//End of another
could anybody pl explain why the output of this code is 10020 ?
My answer to this question was 10010.
1 class Boo{
2 Boo(String s){}
3 Boo(){}
4 }
5 class Bar extends Boo{
6 Bar(){}
7 Bar(String s){super(s);}
8 void zoo() {}
9 Boo f= new Boo() {String s;};
10 }
Does code in line no. 9,creates an instance of Boo or an instance of subclass of Boo?
This is 4 in self test on inner classes from Kathy&Bert book.
public class TestChar
public static void main(String[] args)
byte A = 1;
byte B = \u0041;

The above code compiles and prints 1. But I noticed that if the value of �A�
(can vary from �128 to 127) changes, printed value of B also changes accordingly ie the printed value of B is exactly same as the value of variable �A�.
Actually B has Unicode value that represents character A (\u0041) & byte variable A is referring to value 1 & this is the value printed for variable B.
However if byte B is assigned Unicode value of numbers (0 to 9) ie from \u0030 to \u0039, it prints the no.s 0 to 9 correspondingly.

The same thing happens in following cases.
byte B =3;
byte x=\u0042; // as this represents Unicode value of letter B
System.out.pritln(x); //prints 3
byte Z=8;
byte x=\005A; // this represents Unicode value of Z
System.out.pritln(x); //prints 8
This is true for letters from A to Z with Unicode value ranging from \u0041 to \005A & a to z with Unicode values ranging from \0061 to \007A.
Why is this happening here?
Thanks for the reply.I would like to know whether such questions appear in the exam(scjp 1.4)especially the ones which are identified as bugs.
Thank you once again
Could somebody pl explain me why this code is not throwing runtime exception when i am trying to invoke start() on dead thread and also when getName() method is called on dead thread it is not responding as we can call methods on the dead thread instance except start().
class NameRunnable implements Runnable{
public void run(){
System.out.println("NameR running");
System.out.println("run by" +
public class NameThread{
public static void main(String args[]){
NameRunnable nr=new NameRunnable();
Thread t=new Thread(nr);
catch(InterruptedException e){
System.out.println("main thread complets");