Advertisements
Advertisements
प्रश्न
Give an example of instance variables.
कोड लेखन
उत्तर
class Cuboid {
private double height;
private double width;
private double depth;
private double volume;
public void input(int h, int w, int d) {
height = h;
width = w;
depth = d;
}
public void computeVolume() {
volume = height * width * depth;
System.out.println("Volume = " + volume);
}
}
Height, width, depth, and volume are instance variables.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 6: Class as the Basis of all Computation (Objects and Classes) - EXERCISES [पृष्ठ ३८४]