Why am I having Errors on the Method?

I don't understand why I'm getting these errors in the setInitialQuantity method declaration, does anyone mind taking a look?

public class Invoice
{
    private int quantity;
    private String partNum;
    private String partDesc;
    private double unitPrice;


    //constructor 
    public Invoice ( int initialQuantity, String partNumber, String partDescript, double unitPrice)
    {
        public void setInitialQuantity ( int initialQuantity )
        {
            quantity = initialQuantity;
        }   
    }//end Invoice constructor
}

Errors:

javac Invoice.java
Invoice.java:16: illegal start of expression
    public void setInitialQuantity ( int initialQuantity )
    ^
Invoice.java:16: illegal start of expression
    public void setInitialQuantity ( int initialQuantity )
           ^
Invoice.java:16: ';' expected
    public void setInitialQuantity ( int initialQuantity )
                                  ^
Invoice.java:16: ';' expected
    public void setInitialQuantity ( int initialQuantity )
                                                        ^
4 errors

Answers


You can't have a method inside another (or a Concstructor) in Java, move it outside the constructor but inside the class.

public class Invoice
{
    private int quantity;
    private String partNum;
    private String partDesc;
    private double unitPrice;


    //constructor 
    public Invoice ( int initialQuantity, String partNumber, String partDescript, double unitPrice)
    {
    }//end Invoice constructor

public void setInitialQuantity ( int initialQuantity )
    {
            quantity = initialQuantity;
    }   

}

You can't define method inside another method.

//constructor     
public Invoice(int initialQuantity,String partNumber,String partDescript,double unitPrice)
{
   this.quantity=initialQuantity;
   this.partNum=partNumber;
   this.partDesc=partDescript;
   this.unitPrice=unitPrice;
}   
public void setInitialQuantity(int initialQuantity)
{
    quantity = initialQuantity;
} 

Need Your Help

TAPI lineGetCallInfo returning empty results

c# struct vb6 marshalling tapi

I'm attempting to build a custom solution to interact with our IP Office phone system. I was able to find and update an old VB6 TAPI project provided by our phone provider Avaya which utilizes the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.