java - "Non-static variable degrees cannot be referenced from a static context"? -


this question has answer here:

i in stages of java programming , keep getting compiler error mentioned in title. here main method code:

public class temperature {   public double degrees;   public char scale;   public double degreesc = (5*(degrees - 32))/9;   public double degreesf = (9*(degrees)/5) + 32;   temperature temp1 = new temperature(degrees);    public static void main(string[] args)   {     temperature gtf = new temperature();       gtf.gettemperaturefahrenheit();     temperature gtc = new temperature();       gtc.gettemperaturecelsius();     temperature sd = new temperature();       sd.setdegrees(degrees);     temperature ss = new temperature();       ss.setscale(scale);     temperature sds = new temperature();       sds.setdegreesscale(degrees, scale);     temperature eqls = new temperature();       eqls.equals(temp1);     temperature gt = new temperature();       gt.greaterthan(temp1);     temperature lt = new temperature();       lt.lessthan(temp1);     temperature ts = new temperature();       ts.tostring();   } 

i keep getting compiler error whenever try pass in "degrees", "scale", or "temp1" each of method calls. know why? appreciated!

*note: of methods (like gettemperaturefahrenheit, setdegrees, etc.) provided professor , not allowed change them, , non-static.

problem main() static variables such degrees, scale,etc non-static/instance variable don't exist without creating instance of class. need instance of class temperature in order use within static block, here i.e. main(), e.g. sd.setdegrees(gtc.degrees);


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -