⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example.java

📁 软通公司培训的课件和习题里面有答案。。。
💻 JAVA
字号:
package com.myclass.src;

public class Example {

	
	// 类的属性
	private double width ;
	private double height ;
	private double depth ;
	
	// 无参数的构造函数
	public Example(){
		
	}
	
	// 有参数的构造函数
	public Example(double width,double height,double depth){
		// this.width  width是从属于这个类的,是这个类的一个属性,是全局的
		// 通过this关键字来区分是全局变量还是局部变量,
		this.width = width ;
		this.height = height ;
		this.depth = depth ;
		
	}	
	
	// 方法
	public void getVolume(){
		double  v = width * height * depth ;
		System.out.println("体积: " + v);
	}
	
	// 改变盒子的形状
	public void changeBox(double width,double height,double depth){
		this.width = width ;
		this.height = height ;
		this.depth = depth ;
	}

	
	public static void main(String[] args) {
	
		//  创建一个盒子
		Example e1 = new Example();
		e1.width = 12 ;
		e1.height = 2.4;
		e1.depth = 1.3;
		e1.getVolume() ;
		
		//  创建一个带有长,宽,高的盒子
		Example e2 = new Example(8,5.5,3.7);
		e2.getVolume();
		
		// 创建了一个盒子以后,我们还可以改变盒子的形状\
		e2.changeBox(7, 6.7, 5.6);
		e2.getVolume();
		

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -