Course Hero Logo

JAVA LAB5.docx - JAVA LAB#05 OBJECTIVE: Write a program...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 3 out of 5 pages.

JAVA LAB#05OBJECTIVE:Write a program that gives volume of a box.SOURCE CODE:class Box {double width;double height;double depth;// This is the constructor for Box.Box(double w, double h, double d) {width = w;height = h;depth = d;}double volume() {return width * height * depth;}}class BoxDemo{public static void main(String args[]) {// declare, allocate, and initialize Box objectsBox mybox1 = new Box(10, 20, 15);Box mybox2 = new Box(3, 6, 9);double vol;// get volume of first boxvol = mybox1.volume();System.out.println("Volume is " + vol);// get volume of second boxvol = mybox2.volume();System.out.println("Volume is " + vol);System.out.println("\n\t MADE BY: SAMEER MOHSIN");System.out.println("\n\t ROLL NO: 2019-CE-008");}}OUTPUT:1MADE BY:SAMEER MOHSINROLL NO:2019-CE-008
JAVA LAB#05OBJECTIVE:Write a program that gives an idea of construtors.SOURCE CODE:class OverloadDemo {void test() {System.out.println("No parameters");}void test(int a) {System.out.println("a: " + a);}void test(int a, int b) {System.out.println("a and b: " + a + " " + b);}double test(double a) {System.out.println("double a: " + a);return a*a;}}

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 5 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
NoProfessor
Tags
Subroutine, SAMEER MOHSIN

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture