Hi to all,
It’s one of the question in test, I am confused please someone help.
MainClass{
Public static void main(String [] a){
Employee e=new Employee();
for(int i:e){
// Something
}
Now If I compile this code I will get an error. But without changing for each condition I want to construct an Employee class and solve the error.
In foreach only I can iterate over an array or Iterable. Then how it’s possible.
Thanks,
sasikrishnasamy
0
Newbie Poster
Recommended Answers
Jump to PostIn order to use foreach, the collection your iterating over needs to implement Iterator. Also, the datatype inside your foreach needs to match whatever datatype the collection is containing.
So, now you know that Employee implements
Iterator
and it iteratates over integers. There are a number of ways you can …
All 3 Replies
Hiroshe
499
Posting Whiz in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
jwenting
1,889
duckman
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.