class C { int x; String y; public C() { this(“1”); System.out.print(“one ”); } public C(String y) { this(1, “2”); System.out.print(“two ”); } public C(int x, String y) { this.x = x; this.y = y; System.out.print(“three ”); } public static void main(String[] args) { C c = new C(); System.out.println(c.x + “ ” + c.y); } }
时间: 2023-06-01 15:06:11 浏览: 34
这是一个Java语言问题,具体是在创建一个名为C的类,并定义了三个构造方法,同时在main方法中创建了一个C类的对象,并输出其属性x和y的值。但是没有提出具体的问题。您需要再次提出具体的问题以便我能给予回答。
相关问题
public class CCC { protected int x ; public CCC ( int x ){ this . x = x ; public ccc (){ this . x =0; public void printX ( int x ){ System . out . printin ( x ); public void printX (){ System . out . println ( x ); public class DDD extends CCC { private int x ; public DDD ( int x ){ super . x =0; this . x = x ;public void printX ( int x ){ System . out . printIn ( this . x ); System . out . println ( x ); public void printX (){ System . out . println ( x ); public void print (){ super . printX (); super . printX (2); this . printX (6); printX (); public static void main ( String args []){ DDD bb = new DDD (7); bb . print ();
这段代码存在一些语法错误。下面是修正后的代码:
```
public class CCC {
protected int x;
public CCC(int x) {
this.x = x;
}
public CCC() {
this.x = 0;
}
public void printX(int x) {
System.out.println(x);
}
public void printX() {
System.out.println(x);
}
}
public class DDD extends CCC {
private int x;
public DDD(int x) {
super();
this.x = x;
}
public void printX(int x) {
System.out.println(this.x);
System.out.println(x);
}
public void printX() {
System.out.println(x);
}
public void print() {
super.printX();
super.printX(2);
this.printX(6);
printX();
}
public static void main(String[] args) {
DDD bb = new DDD(7);
bb.print();
}
}
```
修正后的代码定义了两个类:CCC 和 DDD。CCC 类有一个成员变量 x,一个带参数的构造函数、一个无参构造函数以及两个成员方法 printX。其中,一个 printX 方法带有一个 int 类型的参数,另一个不带参数。
DDD 类继承自 CCC 类,并添加了一个私有成员变量 x 和一个带参数的构造函数。DDD 类重写了 CCC 类的 printX 方法,并添加了一个叫做 print 的成员方法。
在 main 方法中,创建了一个 DDD 类的对象 bb,并调用了它的 print 方法。print 方法分别调用了父类 CCC 的 printX 方法、带参数的 printX 方法、自己的 printX 方法和不带参数的 printX 方法。
以下代码运行结果为: 7 19 12 请补充以下源代码: public class Test { int x, y; Test(int x, int y) { this.x = x; this.y = y; } public class Test { public static void main(String[] args) { Test pt1, pt2; pt1 = new Test(1.___, 7); pt2 = new Test(5, 2.____); System.out.print(pt1.x + pt2.x); System.out.print(pt1.y + pt2.y); System.out.print(pt1.3.____ + pt2.4.____); System.out.print(pt1.5.____ + pt2.6.____); } }
以下是补充后的源代码:
```
public class Test {
int x, y;
Test(int x, int y) {
this.x = x;
this.y = y;
}
public static void main(String[] args) {
Test pt1, pt2;
pt1 = new Test(1, 7);
pt2 = new Test(5, 2);
System.out.print(pt1.x + pt2.x);
System.out.print(pt1.y + pt2.y);
System.out.print(pt1.x * pt2.y + pt2.x * pt1.y);
System.out.print(pt1.y * pt2.x - pt2.y * pt1.x);
}
}
```
其中,第一个空格填写数字1,第二个空格填写数字2,第三个空格填写"x * y",第四个空格填写"y * x"。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)