The pre constructor initializes the properties of variables in Java

In Java, you can initialize programming variables before calling constructors

public class StockGraph extends JPanel {

    public boolean runUpdates = true;
    double TickMarks = 18;
    double MiddleTick = TickMarks / 2;
    double PriceInterval = 5;

    double StockMaximum;
    double StockMinimum;

    Random testStockValue;

    DecimalFormat df = new DecimalFormat("#.000");

    LinearEquation StockPriceY;

    public StockGraph(int AreaInterval,int Time,int StockID) {

    }
}

What are the properties of these variables?

When tickmarks change, will middletick change dynamically? When are these variables initialized?

In particular, public Boolean runupdates = true Because initialization is not required, stockgraph. Can be called Runupdates to access variables?

Solution

These are instance variables assigned default values

If there is no middletick, the tickmarks available at the middletick initialization time, that is, when the instance is created, will be used

Runupdates without instances cannot be accessed directly (stockgraph. Runupdates) because it is not an instance field, not a static field

Depending on the needs and code readability, there are several ways to initialize fields in Java This article is inspired by this:

Initializing Fields in Java

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>