Computer Science, asked by lakshya6484, 4 months ago

write a java program to take cost of an apple and then print the amount of 8 apples.​

Answers

Answered by imsachinrathore
1

Explanation:

package com.codegym.task.task04.task0402;

/*

Price of apples

*/

public class Solution {

public static void main(String[] args) {

Apple apple = new Apple();

apple.addPrice(50);

Apple apple2 = new Apple();

apple2.addPrice(100);

System.out.println("The cost of apples is " + Apple.applePrice);

}

public static class Apple {

public static int applePrice = 0;

public static void addPrice(int appl) {

applePrice=applePrice+appl;//write your code here

}

}

}

Similar questions