Srikanth CS

Greenhorn
+ Follow
since Apr 10, 2007
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 Srikanth CS

The == operator is suppose to compare the reference of the of the two operands if i am not wrong.
In the following code i understand false being printed for the second println statement but why is that when it comes to arrays it prints true.


class Check1{

public static void main(String args[]){

String s[] = {"1"};
System.out.println(s[0]=="1");//prints true
String d = new String("1");
System.out.println(d=="1");//prints false
}
}


Even if you excute the following code it prints true!!!

int i[] = {1};
Long l[] = {1l};
System.out.println(i[0]==l[0]);//prints true

Please explain.
Thanks in advacne.
Srikanth.C.S
Original code :
1.import java.io.Serializable;
2.class Animal{

3.}
4.class Dog extends Animal{

4.}
5.class NewClass {
6.public static void main(String... a) {

7.Dog[] dogs=new Dog[10];
8.Animal[] animals=new Animal[10];
9.animals=dogs;
10.animals[0]=new Animal();
11.System.out.println(animals[0]);
12.Animal m=new Dog();
13.m=new Animal();
}
}

The exception is due to line no 9.
if you make line no 9. a comment line the program will compile without errors.
Other wise at line no 10. if you call the Dog class constructor that is
animals[0] = new Dog();
the program will compile without error.

Thus assiging the reference type dog to animals caused the error.


Hope i am right......
Original code :
1.import java.io.Serializable;
2.class Animal{

3.}
4.class Dog extends Animal{

4.}
5.class NewClass {
6.public static void main(String... a) {

7.Dog[] dogs=new Dog[10];
8.Animal[] animals=new Animal[10];
9.animals=dogs;
10.animals[0]=new Animal();
11.System.out.println(animals[0]);
12.Animal m=new Dog();
13.m=new Animal();
}
}

The exception is due to line no 9.
if you make line no 9. a comment line the program will compile without errors.
Other wise at line no 10. if you call the Dog class constructor that is
animals[0] = new Dog();
the program will compile without error.

Thus assiging the reference typr dog to animals without inhertance has caused the error.


HOpe i am right......
Class A{
public static void main{
System.ou.println(new int[] {1,2,3,4,5});
}
}

What dose it print in the output screen and why???


Thank you in advance.
Can any one suggest me any question bank for java so that i can check my skills in a particular topic.


thnak you in advance.
the compund assignment operators have the lowest precedence of all the operators in javal allowin the expression on the right -hand side to be evaluated before the assignment
so c * = a+b;
will be x =((c)*(a+b))
Thank you guys the information was very useful and the link as well.
class Check
{
public static void main(Stirngs agrs[])
{
Check c = new Check();
System.out.println(c);
}
}

Now wat is the value that is printed in the output???
Is it any grabage value from the memory?
Will the correct no of options be specified in scjp1.4.
That is for example 3 out of the 4 options are right will the exam be promting to select 3 answers.