alpa urja

Greenhorn
+ Follow
since Dec 27, 2000
Merit badge: grant badges
For More
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 alpa urja

A new string by any methods of String class is only created when something new is created.
so,if we do String str2=str.concat("");//no blank space
no new String is created as nothing new is added or nothing new deleted.So the string is same as the original(ie str).so == will be true
But if String str2=str.concat(" ");//blank spaces included
Here,as you are adding space,a new String is formed in another String pool so,== will be false.
Hope,that serves your purpose

1) objects are eligible for garbage collection after its declared null
2) objects are eligible for garbage collection when the method returns
Both the probabilities are correct because,if before the method gets over or returns,if the object is assigned a null value(and if there are no more references to that object)then it is eligible for garbage collection.The rule(2) is ok generally,that is if the object is not assigned a null value.
Just understand,that the objects created in the method are local to that method,so are eligible for garbage collection once the method is over or is returned.
congratulation!
i am planning to give exam on 25th.
can you please email me on alpa_kapadia_2000@yahoo.com
thanks.
23 years ago
Hi, Ash and a hearty congratualation for a beautiful score.
I am thinking to give the exam within a week's time.If you can forward me the question in your exam I would be grateful to you.
My email-id is urjay24@yahoo.com
Thanks
alpa urja
23 years ago
HI!
A local inner class can acess all the class-level variable ieall the member variable of its enclosing class and only final variables of the method in which it inner class is defined.
String s is a class-level variable ,so accessible
int iam is a local variable of the method(amethod()),so not accessible.

Hope it helps
alpa urja
Regarding inner classes
An inner class can't be volatile,transient,native or synchronized
1)Can inner classes be abstract? YES
EXAMPLE::
class Outer11
{
int x=10;

abstract class inner1
{
abstract public void m();
}
class In extends inner1
{
public void m()
{
System.out.println("of the abstract");
}
}
public static void main(String[] args)
{
Outer11 o=new Outer11();
In i=o.new In();
i.m();
}

}
2)Can they be final?-YES
EXAMPLE::
class Outer11
{
int x=10;

final class inner1
{
public void m(){};
}
class In
{
public void m()
{
System.out.println("of the final");
}
}
public static void main(String[] args)
{
Outer11 o=new Outer11();
In i=o.new In();
i.m();
}

}
3)How to extend them?
AS seen in the first example.
4)If a inner class is static then all the members of it are static implicitly.Is this true?
If the inner class is static means it behaves as a top level class.So it can declare both static and non static members.
If inner class wants to use a static member it must be declared static.

Hope that helps
alpa urja
String s1 = "hello";//1
String s2 = "lo";//2
System.out.println(s1 == ("hel"+"lo")); // true//3
System.out.println(s1 == ("hel"+s2)); // false//4
1.creat new string object in pool.
2.creat new string object in pool.
"hel"+"lo"=hello hello is already in pool so it point to
the same object,
"hel"+s2=hello but create a new object because strings are
immutable so it is false.
here compiler give first priority to == operator so
first check7==4 which will give false so int&boolean
& is not operate on boolean type so it will give an error.
((i&j)==4)//right
I am very much confused about these three.
I read from some book these all are predefined object of subclass of InputStream.
And one more book i read java.lang.System is class
and these three are public variable of that class.
give me clear explanation.
Thanks in advance.
anybody explain me why output like that?
1.class Test{
public static void main(String args[])
{
int i=0;
i=i++;
System.out.println(i);//0
i=i++;
System.out.println(i);//0
i=i++;
System.out.println(i);//0
}
}

2.class Test{
public static void main(String args[])
{
int i=0,s;
s=i++;
System.out.println(i);//1
s=i++;
System.out.println(i);//2
s=i++;
System.out.println(i);//3
}
}
java compiler has problem with you are declared int i as public
there is no problem with public class Test//
Remember you never declare local varible(in method,in static block or simple block) with any access modifier.
bye.......................bye
hello!
congratulation!
can yoy please post me your questions on alpa_kapadia_2000@yahoo.com
23 years ago
hello!
congratulation!
can yoy please post me your questions on alpa_kapadia_2000@yahoo.com
23 years ago
class J5Q14{
public static void main(String Args[]){
for (int i=0; i< 10; ++i){
try{
if( i%3 ==0) throw new Exception("EO");// stat 1
try{
if(i%3==1) throw new Exception("E1");//stat 2
System.out.println(i);
}catch(Exception inner){ //stat 3
i*=2;
} finally {
++i;
}
}catch (Exception outer){ //stat4
i +=3;
}finally{

++i;
}
}
}
}
at stat1
//when i=0,it throws Exception and goes corresponding catch{Exception outer},then i=3 and then executes finally block,so now i=4;Now it goes in the for loop and i=5(because of ++i)
now 5%3!=0 so it does not throw exception at stat1,then the control moves to stat2
again 5%3!=1 so does not throw exception at stat2..
So prints 5
then it excecutes both the finally statments and the i =7,then it moves in the
for loop (before going to the loop ,++i is done) so i=8 and i%3!=0 so does not thrwo exception at stat1,the then the control moves to stat2
again 8%3!=1 so does not throw exception at stat2..
So prints 8.Again executes both the finally statements and the i=10 so does not
go in the loop

Hope that helps

Alpa-urja
This is your code and below is the explanation
class Test{
public static void main(String Args[]){
for (int i=0; i< 10; ++i){
try{
if( i%3 ==0) throw new Exception("EO");// stat 1
try{
if(i%3==1) throw new Exception("E1");//stat 2
System.out.println(i);
}catch(Exception inner){ //stat 3
i*=2;
} finally {
++i;
}
}catch (Exception outer){ //stat4
i +=3;
}finally{

++i;
}
}
}
}
at stat1
//when i=0,it throws Exception and goes corresponding catch{Exception outer},then i=3 and then executes finally block,so now i=4;Now it goes in the for loop and i=5(because of ++i)
now 5%3!=0 so it does not throw exception at stat1,then the control moves to stat2
again 5%3!=1 so does not throw exception at stat2..
So prints 5
then it excecutes both the finally statments and the i =7,then it moves in the
for loop (before going to the loop ,++i is done) so i=8 and i%3!=0 so does not thrwo exception at stat1,the then the control moves to stat2
again 8%3!=1 so does not throw exception at stat2..
So prints 8.Again executes both the finally statements and the i=10 so does not
go in the loop

Hope that helps

Alpa-urja