jaysingh solanki

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

Recent posts by jaysingh solanki

But What if i declare
class as
final class Test{;;;}
Code:
class Test {
int count;
public void write()
{
System.out.println("number of count"+count);
}
public static void main(String arg[])
{ Test t=new Test();
t.write();//ok
System.out.println(t3.write());//line1
}
}
Q1: -If the method return value then we get output atline1
but in the case when the method is void and if we try to do this
in line1:Incompatible for mehtod can't convert void to char[]
what it means.//end
Q2:Accessibility modifier
If no Accessibility modifier is given
to class and members then they accessible
for classes in the same package and subclass.
code:
class Pass
{

public static void main(String arg[])
{ int arr[]={1,2,3,4,5};
arr[0]=arr[3];
for (int i=0;i<arr.length;i++)
System.out.println(arr[5]);//line 1
}
}
My auestion is:
when i compile the programe
it compile ,but gives error
in winNT that application error
is occure.you dont think it
should give ArrayIOOBExcep.
If i change line one arr[4] than it print 5 five times;
20 years ago
code:
class Pass
{
public static void main(String arg[])
{
int[][] i={{1,2,3},new int[]{3,4,5},{333},{},{6,7,8}};//line1 ok
int[][] i1={{1,2,3},new int[][]{1,2,3},{4,4,3}}; //line2notok
int i2[]={{1,2,3},new int[][]{2,3,4},{4,5,6}};//line3notok
int i3[]={{1,2,3},new int[]{1,2,3}};//linenot5
System.out.println();
}
}
My question is why this three
lines give compile time error
please anyone explain me;
20 years ago
code:
class Test
{
int i=4;
i+=5;//line 1
public Test()
{
System.out.println(i);
}
public static void main(String arg[])
{
Test t=new Test();

}
}
My question is why line one gives compile time error
identifier exp.
code:
class Test
{
public static void main(String arg[])
{
byte i=-42;
int n=i>>4;//line1 -42/2power4
byte l=12;
int m=12>>4;//line2 12/2power4
byte j=34;
int k=j>>3;//line3 34/2power3
System.out.println(n+""+m+""+k);
}
}
output:-3 //-42/2power4 //confuse
:0// 12/2power4 //ok
:4 //34/2power3 //ok
Respected sir
for line1 after calculation
how this result come -3 i think it -2.If
i performe this with 42 the
result is 2, is the result is round.
Thanks hari now my concept is clear
code:
class T
{
public static void main(String arg[])
{
boolean b1=false,b2=false,b3=true;
b1&=true;//line1
b2|=b1; //line2
b3^=b2|=b3;//line3
boolean b4=false | false;//line4
System.out.println(b1+"\n"+b2+"\n"+b3+"\n"+b4);
}
}
output:false
:true
:false
:false
My Question:why line2 is true.If line2 is true
than line4 also true.
code:
class Test
{
public static void main(String arg[])
{ Test t=new Test();
final short j=2;//line 1
byte b=j;
System.out.println(b);
}
}
Respected sir

I assign the value 128 to int and explicit cast need
but why cast is needed for short i declare it final
[ December 02, 2003: Message edited by: jaysingh solanki ]
cosde:
public class Lit{
public static void main(String[] argv){
int i = 18;
int j = 022;//Octal version: Two eights plus two
int k = 0x12;//Hex version: One sixteen plus two
long f=1.2L;
System.out.println(i);
System.out.println(j);
System.out.println(k);
System.out.println(f);
}
}
My Question:How i assign long value to f
if i put 1.2L or 1.2l it give
error Invalid character in number.
Respected sir
code:
class MyClass{
static long p=3;
p=p+6; //line 1
public static void main(String argv[]){
String b="5";
b+="3";//line 2
System.out.println(p);
System.out.println(b);
}
}
my question:when i am using += for member variable then it ok
the output is 53, but if i use for class level variable
then it gives identifier expected.please give reason.
String s1,s2,s3,s4
s1=new String("hello");
s2=new String("hello");

s1.equals(s2);//ok
s3=s1.intern();
s4=s2.intern();
if(s3==s4)//ok
But if i do:-
if(s1==s3)//not ok(not refer to same object);
if(s2==s4)//not ok
when String method intern is invoke on the
String object,it return a reference to a String object that
is guaranteed to have the same contant,However,String
s1 and String s2 have the same contents,the reference
returned by this call to intern is a reference to the
String object returned by s1.intern() and s2.intern().But s1==s3 and
s2==s4 give that they are not refer to same object,Why?;
//Code:Sup
public class Sup
{
protected int x,y;
//no argument constructor
public Sup()
{
x=0;
y=0;
}
public Sup(int a,int b)
{
x=a;
y=b;
//implicit calling toString()
System.out.println(this);
}
public String toString()
{
return "["+x+","+y+"]";
}
}
_______________________________________________________________________
//Code:Sub
public class Sub extends Sup
{
protected double radius;
//no argument constructor
public Sub()
{
//implicit call Super construtor
radius=0;
System.out.println(this);
}
public Sub(double r,int a,int b)
{
super(a,b);
radius=r;
//implicit calling toString()
System.out.println(this);
}
public String toString()
{
return "["+super.toString()+"+"+radius+"]";
}
}
___________________________________________________________________________
//Code:Test
public class Test
{
public static void main(String arg[])
{
Sub b=new Sub(4.5,64,32);
Sub c=new Sub(10,5,5);
}
}
And the output is:[[64,32]+0.0]//line1
[[64,32]+4.5]//line2
[[5,5]+0.0]//line3
[[5,5]+10]//line3
Respected sir,
My question is :The application invoke main by instant
Sub object b.This invoke Sub costructor second
which immediatelly invoke the Sup constructor second
The Sup constructor output the value received from the
Sub constructor by implicitly calling method toString
and return programe conrol back to the Sub constructor.Then
the Sub constructor output the value by calling toString,same
for Sub c.My question is how the radius become 0.0 in line 1,3.
how it print line 1,3;hope to hear from you.
public class MyClass{ public static void main(String[] args){ final int i = 100; byte b = i; System.out.println(b); }}
Respected sir,
I want to know that without declaring final it give cast problem but after
declareing final to int it print 100 why?