Ritwik Saini
Ritwik Saini

Reputation: 29

There is no output for the same:

When I compile and try to run this in eclipse there is no output. I have been trying every way possible.

class let {

    String name;
    int age;
    int rollno;
}

public class class_method  {

   public static void main(){

       let person1 = new let();
       person1.name = "Ritwik";
       person1.age = 14;
       person1.rollno = 20;

       System.out.println( " Hello my name is :" + person1.name);

       Scanner s = new Scanner(System.in);
   }
}

Upvotes: 0

Views: 58

Answers (2)

Saurabh Mishra
Saurabh Mishra

Reputation: 296

you are facing this behavior because of the signature of your main method
In java it is compulsory for the main method to have following signature

public static void main(String args[]) { //Lots of code here }

For more details, look here

Update

This is why String[] args is important in main function definition. Following is an excerpt from oracle docs that I have posted a link to

The main method accepts a single argument: an array of elements of type String.

This array is the mechanism through which the runtime system passes information to your application.

Upvotes: 4

Arjit
Arjit

Reputation: 425

You are forgetting the String[] args in main method argument.

Try this.

import java.util.Scanner;

class let {

    String name;
    int age;
    int rollno;
}

public class ClassMthod  {

   public static void main(String[] args){

       let person1 = new let();
       person1.name = "Ritwik";
       person1.age = 14;
       person1.rollno = 20;

       System.out.println( " Hello my name is :" + person1.name);

       Scanner s = new Scanner(System.in);
   }
}

Upvotes: 0

Related Questions