kavundamani senthil

Greenhorn
+ Follow
since Feb 28, 2008
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 kavundamani senthil

I'm able to access the instance variables, by why is this code throwing a ClassCastException ???

import java.util.*;
public class sorting {
String bankName ;
int accId;
public void addaccount(String bankName,int accId)
{
this.bankName = bankName;
this.accId = accId;
}
public static void main(String args[])
{
Set t = new TreeSet();
sorting s = new sorting();
sorting s1 = new sorting();
sorting s2 = new sorting();
sorting s3 = new sorting();
s.addaccount("IndianBank",100);
s1.addaccount("IndianBank",99);
s2.addaccount("IndianBank",200);
s3.addaccount("Bank ofindia",234);
t.add(s);
t.add(s1);
t.add(s2);
Iterator it = t.iterator();
while(it.hasNext())
{

sorting o = (sorting)it.next();
System.out.println(o.bankName);
System.out.println(o.accId);

}
}
}
In the program below how can i access the fields bankName, accId from the object o ?

import java.util.*;
public class sorting {
String bankName ;
int accId;
public void addaccount(String bankName,int accId)
{
this.bankName = bankName;
this.accId = accId;
}
public static void main(String args[])
{
TreeSet t = new TreeSet();
sorting s = new sorting();
sorting s1 = new sorting();
s.addaccount("IndianBank",100);
s1.addaccount("IndianBank",99);
t.add(s);
t.add(s1);
Iterator it = t.iterator();
while(it.hasNext())
{
object o = it.next();}
}
}
15 years ago
How can we instantiate, access the methods in an anonymous inner class
(all three types) ???
thanks a lot Hrishikesh and Prabhat.
so can we conclude that staticmethods can always be called with instances of their classes apart from calling them with their class names ???
In the program below i'm accessing the staticmethod with the instance of the class which is incorrect and has to throw an error. But it compiles fine and gives the output also correctly why is that so ?

public class example {
public static void main (String [] args) {
Animal a = new Animal();
a.num=20;
a.somemethod();
System.out.println("a.num is 20"+a.num);
}
}
class Animal {
static int num=10;
public void eat() {
System.out.println("Generic Animal Eating Generically");
}
static void somemethod()
{
System.out.println("xxx");
System.out.println("this is somemethod");
}
}
when i try to declare a static variable inside a static method it shows an error as illegal start of expression. is it legal to do so

public class Test {
static int zee=5;
public static int amethod(){
static int zoo=7;
int x =1;
return x;
}
public static void main(String argv[]) {
System.out.println("I love Zamples and J2SE 6!");
int y= amethod();
System.out.println(y);
Test z = new Test();
System.out.println(zee);
}

Test.java:7: illegal start of expression static int zoo=7; ^ 1 error
16 years ago
Please give me some sample code used for generating a table dynamically using DOM onclick of a button.
Hi ppl,

is this a valid use of java assignment operator

y+=(y=1)

what is the value if it is so ?

regards,
Senthil
can we use implements keyword in a class that has argument defined anonymous classes ?
can we put an arraylist of objects in 1.4 using generics ..

is generics required for scjp 1.4