Results 1 to 3 of 3
  1. #1
    sreeram is offline Member
    Join Date
    Dec 2012
    Location
    Hyderabad
    Posts
    4
    Rep Power
    0

    Default Execute main class constructor

    Java Code:
    interface as 
     {
        void d();
     }
    /*class qwe implements as
    {
    	public void d()
    	{
    		System.out.println("Hello World");	
    	}
    }
    */
    public class Interfaces implements as{
    	static int i=2,j;
    	public  void d()
    	{
    		System.out.println("Hello world");
    		
    	}
    Interfaces()
    {
       System.out.println(" the what ..?");
       
    }
    public static void main(String args[])
    {
    	
      d();  //Cannot make a static reference to the non-static method d() from the type Interfaces...
      // qwe q=new qwe();
      // q.d();
       System.out.println(i);
    }
    }
    how to make a static reference???

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Execute main class constructor

    You don't in fact want to make a static reference. The best course of action is to create an Interfaces object, and then call the d() method on that instance.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Execute main class constructor

    The method 'd' can only be executed in assocation with an object.
    You need to create an Interfaces object (new Interfaces()).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Execute main args.length number of times
    By cherrychives in forum New To Java
    Replies: 3
    Last Post: 10-05-2012, 06:03 AM
  2. Replies: 4
    Last Post: 07-10-2012, 05:47 PM
  3. Running main method class from another main class
    By tlrocketman in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 08:30 AM
  4. Replies: 0
    Last Post: 12-19-2007, 09:10 AM
  5. Replies: 0
    Last Post: 12-19-2007, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •