1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
natita [175]
3 years ago
11

Find the error and rewrite the code with the error fixed.

Computers and Technology
1 answer:
kap26 [50]3 years ago
7 0

Answer:

Explanation:

1st mistake: Barcode is written with upeer case, that's not the convention for variables in java, only classes.

2nd: Barcode is public, it is convention to always leave variables private then create getters and setters in case you need to change the value but never acess the variable outside the class it belongs. Also the class should at least have a default constructor in case you are going to instantiate an object outside it.

so the product class should be:

--------------------------------------------------------------------

public class Product {

private int barcode;

        public Product() {

        // default constructor

        }

public int getBarcode() {

 return barcode;

}

public void setBarcode(int barcode) {

 this.barcode = barcode;

}

}

-------------------------------------------------------------------------

3rd: in the main class now you can instantiate the 2 objects but you are gonna set the variable and get the value through the method, like this:

public class Main {

 

public static void main(String[] args) {

   

 Product prod1 = new Product();

 prod1.setBarcode(123456);

 Product prod2 = new Product();

 prod2.setBarcode(987654);

 System.out.println(prod1.getBarcode());

 System.out.println(prod2.getBarcode());

}

}

-----------------------------------------------------------------------------------

Assuming the 2 classes (main and product) are in the same package. But in case they are in different packages, just make sure to import the Product class into the Main class so that you can instantiante an object (new Product()) of it.

You might be interested in
What does a file extension tell you?
kiruha [24]

A. because everyone basically has seen it..

3 0
3 years ago
I'm doing a python assignment for my coding class, and the input part just isn't working, someone please help out and tell me wh
tigry1 [53]

,.....,.........mm malds quería saber

8 0
2 years ago
What happens? In word 2016 when the home ribbon tab is clicked on ?
RideAnS [48]

When you clicked on the ribbon tab in word 2016, you'd be brought to the home tab, where all of the basic controls are displaced for you to see.

Hope I could help! :)

5 0
3 years ago
Read 2 more answers
Jack is using a document that has multiple references to his company as Company ABC, LLC. He would like to change these values t
Alinara [238K]

Copy the text you want to use as a replacement and use the Find dialog box to find each value to paste the replacement text.

Explanation:

4 0
3 years ago
Read 2 more answers
A rear drum brake is being inspected. The primary shoe is not contacting the anchor pin at the top. Technician A says that this
sergeinik [125]
The answer is B :).
6 0
3 years ago
Read 2 more answers
Other questions:
  • Assume the availability of a function called printStars. The function receives an integer value as an argument. If the argument
    8·1 answer
  • How many bits are required to write decimal number?
    9·1 answer
  • In the following project, you will edit a worksheet that will be used to summarize the operations costs for the Public Works Dep
    12·1 answer
  • What is out put.what is data. what is microprocessor
    14·1 answer
  • When creating a mail merge, you must insert all of the items from your data source into your merged document. Truth or false ?
    6·2 answers
  • 3. By default, Blender® remembers your last 32 actions and allows you to undo them one at a time by pressing CTRL+Z. (1 point)
    9·1 answer
  • Which of these is an aggregator?
    5·2 answers
  • Select the correct answer from each drop-down menu
    6·2 answers
  • Which of the following is a Microsoft solution
    11·1 answer
  • Python 4.5 code practice
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!