Answer to Question #307806 in Java | JSP | JSF for Ali

Question #307806

In Java , Write a class Marks with three data members to store three marks. ... Create two constructors and a method to calculate and return the sum 

1
Expert's answer
2022-03-08T09:38:56-0500


class Marks {
	private int mark1;
	private int mark2;
	private int mark3;


	public Marks() {
		this.mark1 = 0;
		this.mark2 = 0;
		this.mark3 = 0;
	}


	public Marks(int mark1, int mark2, int mark3) {
		this.mark1 = mark1;
		this.mark2 = mark2;
		this.mark3 = mark3;
	}


	public int markSum() {
		return mark1 + mark2 + mark3;
	}
}


class App {


	public static void main(String[] args) {
		Marks marks = new Marks(50, 60, 80);
		System.out.println("Marks sum: " + marks.markSum());


	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS