Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 04:54 PM
Member
 
Join Date: Jul 2007
Posts: 39
Rep Power: 0
christina is on a distinguished road
Default non-static member can not be referenced from a static context
If for every program I write a main function , which is a static method how am I supposed to call other non static functions from that?
thanks
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-31-2007, 07:11 PM
Senior Member
 
Join Date: Jul 2007
Posts: 135
Rep Power: 0
brianhks will become famous soon enough
Default
Instantiate the object.

Code:
public class MyObject
{
private void privateMethod() { /*do stuff*/ }

public static void main(String[] args)
{
MyObject mo = new MyObject();
mo.privateMethod();
}
}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-20-2009, 12:45 AM
Member
 
Join Date: Mar 2009
Posts: 2
Rep Power: 0
rock_star is on a distinguished road
Default
christina,

brian has answered your question but why do you want to have main method for each class?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-20-2009, 01:35 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,453
Rep Power: 8
Fubarable is on a distinguished road
Default
Even more important: why are you asking this question in a thread from 2007?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Static Variables Java Tip java.lang 0 04-17-2008 12:08 AM
Explicit static initialization with the static clause Java Tip java.lang 0 04-17-2008 12:07 AM
Static class eva New To Java 1 12-31-2007 02:02 PM
Error: Non-static method append(char) cannot be referenced from a static context paul Advanced Java 1 08-07-2007 06:05 AM
Error: non-static variable height cannot be referenced from a static context at line fernando AWT / Swing 1 08-01-2007 10:25 PM


All times are GMT +2. The time now is 02:59 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org