Hello,
In my code, I have the below output. but I expected to execute the first printf then get two integers from the console.
(Run in Netbeans - Widnows 10)
import java.util.Scanner; class square { protected int height; protected int width; protected int surfaceArea; public square(){} public square(int h, int w) { height = h; width = w; } public void ComputeSurfaceArea() { surfaceArea = height*width; System.out.printf("Square Area is: %d\t",surfaceArea); } } class cube extends square { private int depth; public cube(int d) { depth = d; } @Override public void ComputeSurfaceArea() { surfaceArea = 6*(depth*depth); System.out.printf("Cube Area is: %d\t",surfaceArea); } } public class NewClass { public static void main(String[] args) { int w,h; Scanner sc = new Scanner(System.in); System.out.printf("\nWidth & Height: "); w = sc.nextInt(); h = sc.nextInt(); square mySquare = new square(w,h); mySquare.ComputeSurfaceArea(); System.out.printf("\nCube: "); int d = sc.nextInt(); cube myCube = new cube(d); myCube.ComputeSurfaceArea(); } }
2
3
Width & Height: Square Area is: 6
8
Cube: Cube Area is: 384