Md. Nazrul Islam Md. Nazrul Islam - 5 months ago 38
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());


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();