puneet pruthi

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

Recent posts by puneet pruthi

Hi there!!
I read this some where and i want to clear my doubts abt it.Can i define a class inside an interface?If yes where can i use itor where do i use it for?
thank you.
23 years ago
Hi alex,
if u wud have a look at complete reference by patrick nortaon,the concept will b more clear to you.If u can't do that then we can discuss it here only.
23 years ago
Hi alex,
if u wud have a look at complete reference by patrick nortaon,the concept will b more clear to you.If u can't do that then we can discuss it here only.
23 years ago
I appeared for java certification on 20 of march and cleared it .But till date i haven't recd my certificate.KIndly someone will tell me whom can i contact for that.Is there any customer care or something,coz the prometric centre where i gave the exam,they say now its up to me and the sun people ,they have no role to play inbetween.
thank you
puneet
the filter inputstream constructor takes an argument of inputstream
u can create it like
filterinputstream fis=new filterinputstream(new fileinputstream("abc");
P.S c the capital f or i or s on the name!!
public class X {
public static void main(String args[] ) {
A[] arrA;
B[] arrB;
arrA =new A[10];
arrB = new B[20];
arrA=arrB; //1
arrB=(B[])arrA; //2
arrA= new A[10];
arrB =(B[]) arrA; //3
}
}
Hi !!
it wont show class cast exception at 2 bcoz,at 1 arrA is pointing towards B.arra has now the address of B.So it wont throw any exception.
Before 3,u r creating a new object of A.it doesn't contain any address of B.
There is one simple rule for class cast exception,which i have discoverd and it works fine.
(Cast)X,wont throw any exception if x is instance of Cast.If it is not then it will.
Now at one arra points towards B.So arrA is instanceof B.At three ,this is not the case.And arrA instanceof B returns false,hence classcast exception.
hope this will clarify your doubt.
Which of the following are legal statements?
1) float f=1/3;
2) int i=1/3;
3) float f=1.01;
4) double d=999d;
----------------------
I could not understand y opt) 1,2 are also correct in addition to option 4.
hi friends!!
option 1,2 and 4 r correct .A double cant b assigned to an int as an int of 32 bits cant store double of 64 bits or u have to cast it.
in the first option 1/3 1 is an int and 3 is also taken as an int so the operation involves int/int which returns an int and since an int can b stored in a float,therefore it is correct.
second option is also correct as it also returns an int and the result is stored in an int(ans will b 0).
Third option is false coz 1.01 is double by default and u cant store double in float(1.01 is taken as 1.01d).it will run fine if u rite 1.01f.
fourth is no problem,it will run fine without riting a d suffix.
hope u got that!!
Hi!!
constants which r in range wont throw any error.like byte b=10;though 10 is in range ,still the compiler knows that it is a constant whose value is not going to change and it is within limits so it is okie
another thing which will work is
final int j=30;
byte b=j;
this will also work fine.
Hi shilpa,
Abt the layouts,suppose u have initially borderlayout and u have added buttons to it,specifying flow or grid layout ,would override it and the components will b placed acc to the new layout.
but if u have flow layout and u give borderlayout afterwards,it wont override ,but give a completely new layoutwhich is blank.It will enclipse the previous layout with the components.
Why this happens ,i dont have a clue,i read it some where but no reasons were given.
Hi shilpa!
the confusing thing is the method another(valhold v,int i),it has used the same name v ,which is different from original v.Let us take it as v1.Now when we call this method,v1 is also pointing to the i of v ,when we set v1.i=20(originally v.i in the question),the i of main v also gets value 20.Then the value of v1 is pointed to vh,which has nothing to do with original v whose value is set to 20.Hence it gives twenty.
hope u get it.Any doubts u can mail me at puneetpruthi@usa.net
Hi gunjan
remember two main facts abt casting
1.At compile time,it will check if the two objects can denote an object of a class,where this class is subtype of both source and destination.
Otherwise it will give compile time error.
2.if it compiles then at run time it will check for the cast.
suppose the cast is
(abc)dest
if dest instanceof abc returns true,then it is a valid cast otherwise it will give class cast exception.
Inner classes can have any level of nesting. What would be the right way to create an instance of inner-most class if we have three levels of nested class like;
class outer
{
class inner
{
class inner1
{}
}
void temp()
{
outer.inner i = new outer.inner();
//Compiler Error outer.inner.inner1 j = new outer.inner.inner();
//Compiler Error inner1 k = new inner1();
}
}
Hi tanveer,
Non static inner classes need an instance of outer class.
and since u r creating the instance of inner inside the outer class itself,u dont need to write outer.inner i,this wud also work
inner i=new inner();which is like
inner i=this.new inner() coz non ststic method wud place 'this' implicitly.
to create the instance of inner class u need it to define
inner.inner1 j=new inner().new inner1();
which is equavalent to
inner.inner1 j=this.new inner().new inner1();
hope this will clear your doubt.
thanx naveed!!
u for clearing my doubt!!
Hi all,
i am having problem with this code
class abc{
public static void main(String args[]){
int i=0;
int []a={3,6};
a[i]=i=9;
System.out.println(i+""+a[0]+""+a[1]);
}
}
as the assignment operator works from right to left ,this shud give arrayout of bound error.But it runs smoothly!!