This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes Confusion on code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Confusion on code" Watch "Confusion on code" New topic
Author

Confusion on code

Sushanta Chakrabarty
Greenhorn

Joined: Dec 05, 2007
Posts: 4
public class DDg {

public static void main(String[]args){
fgh f = new fgh();
f.fgr(new Iface(){ public void ggg(){System.out.println("a");}});

}

}
interface Iface{
void ggg();

}
class fgh{
void fgr(Iface I){System.out.println("b");}
}

In the above mentioned program I think I should get "a" as output but I am getting "b". May anyone help?
HarrySingh
Greenhorn

Joined: Nov 29, 2007
Posts: 1
f.fgr(new Iface(){ public void ggg(){System.out.println("a");}});

You are calling fgr() method which takes instance of Iface which is an interface so you have to create an anonymous inner class inside the argument BUT you are never made a call ggg() in your code.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Confusion on code
 
It's not a secret anymore!