构造方法
来源:互联网 发布:g76内螺纹编程实例 编辑:程序博客网 时间:2024/06/06 05:04
/**
* @author Rory
* @category 创建三个构造方法 执行不同的操作 在main方法中测试函数的调用
*/
public class Gouzao {
int a,b;
double c,d,e;
String f,g;
//传递两个整数值并找出其中最大的那个
public Gouzao(int a,int b){
this.a=a;
this.b=b;
if(a>b){
System.out.println("最大值是"+a);
}else{
System.out.println("最大值是"+b);
}
}
//传递三个double值并求出其乘积
public Gouzao(double c,double d,double e){
this.c=c;
this.d=d;
this.e=e;
double k=c*d*e;
System.out.println("三者的乘积是"+k);
}
//传递两个字符串并检查是否相同
public Gouzao(String f, String g) {
super();
this.f = f;
this.g = g;
if(f==g){
System.out.println("这两个字符串是相同的");
}else{
System.out.println("他们是不相同的");
}
}
* @author Rory
* @category 创建三个构造方法 执行不同的操作 在main方法中测试函数的调用
*/
public class Gouzao {
int a,b;
double c,d,e;
String f,g;
//传递两个整数值并找出其中最大的那个
public Gouzao(int a,int b){
this.a=a;
this.b=b;
if(a>b){
System.out.println("最大值是"+a);
}else{
System.out.println("最大值是"+b);
}
}
//传递三个double值并求出其乘积
public Gouzao(double c,double d,double e){
this.c=c;
this.d=d;
this.e=e;
double k=c*d*e;
System.out.println("三者的乘积是"+k);
}
//传递两个字符串并检查是否相同
public Gouzao(String f, String g) {
super();
this.f = f;
this.g = g;
if(f==g){
System.out.println("这两个字符串是相同的");
}else{
System.out.println("他们是不相同的");
}
}
}
/**
* @author Rory
* @category 构造方法测试
*/
public class GouzaoTest {
public static void main(String[] args) {
Gouzao gouzao1=new Gouzao(23, 21);
Gouzao gouzao2=new Gouzao(1.1, 2.0, 3.1);
Gouzao gouzao3=new Gouzao("部同", "部同");
}
}
0 0
- 构造器(构造方法)
- 构造方法/构造器
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 构造方法
- 新建IAR_stm32工程
- 使用popupWindow时,当点击listView,没有效果
- Ubuntu下为Python3.x安装pygame
- Java学习笔记之单例模式
- zynq开发中如何向文件系统里添加自己的程序
- 构造方法
- android虚拟按键适配
- 通过控件子类化实现Edit Control接收Enter按键
- git 自动转换行符的坑爹案例
- MaskFilter
- 初识Zigbee
- Chapter 8 浅析CountDownLatch类
- 原型模式设计克隆人
- 【数据结构】红黑树