Md. Nazrul Islam Md. Nazrul Islam - 1 year ago 71
Java Question

Why cant i call fu() from main method

public class NewClass {

static int x;
class Duck{
int y;
int fu(){
return x+y;


public static void main(String[] args) {

System.out.println(new Duck().fu());

Answer Source

Your problem is that you're trying to create a Duck object but Duck is enclosed in NewClass so you must first create a NewClass object (Or make them both static)

try this

public static void main(String[] args) {
    Duck d = new NewClass().new Duck();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download