Kiran Sharma

Greenhorn
+ Follow
since Dec 09, 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 Kiran Sharma

Hi Navin!
I too would like to know the same.
Plz mail me at kiran_kr@rediffmail.com.
Thanks in advance.
Hi, I guess its false, At the most u can make an object
'eligible' for g/c.But whether/when the object will be
g/c'd is the prerogative of the jvm and not the programmer.
Plz. correct me if i am wrong.
// IncTest.java
public class IncTest {
int i=3,k=0;
public void SomeMethod (){
k= ++i * ++i * ++i ;
System.out.println("i = "+i +"k= "+k);
}
public static void main (String args[]){
IncTest obj = new IncTest();
obj.SomeMethod();
}
}
_________________________________
output i = 6 k= 120
------------------------
//IncTest.c++
#include<iostream.h>
void main(){
int i = 3 , k=0 ;
k = ++i * ++i * ++i ;
cout << "i = "<< i;
cout << "k = "<< k;
}
__________________________________________________
output : i = 6 k = 216
The second o/p seems obvious since the precedence of '++' is higher than '* ' so first 'i' is incremented to 6 & then
6 * 6 * 6 is 216.
Then why is is o/p in IncTest.java different.

Thanks guys ! That did solve my second querry , but @ the first
I wud like to know what forms the basis of the C'tor A(int i)
in class A being invoked & not A ().
( A () is invoked by A(int i) thru this() )
23 years ago
Can any one plz. clarify my concepts on constructor invocation order/priority with reference to following code.

-------------------------
class A {
A()
{
System.out.println("A.A called");
}
A(int i) {
this();
System.out.println("A.A(int) called");
}
}

class B extends A {
int i = f();
int j;

{
j = 37;
System.out.println("initialization block executed");
}

B() {
this(10);
System.out.println("B.B() called");
}

B(int i) {
super(i);
System.out.println("B.B(int) called");
}

int f() {
System.out.println("B.f called");
return 47;
}
}

public class CtorDemo {
public static void main(String args[]) {
B bobj = new B();
}
}
1 . Why does the C'tor A(int) get preference over A() in class A
while B() over B(int) in class B ?
2 . Also if I use this() in A() instead of A(int) C'tor
(or in B(int) instead of B()) i get "Recursive constructor invocation"
error , plz clarify my this() funda .
23 years ago