你好,我的第3题代码出来了,可以直接运行
public class Test1 {
public static void main(String[] args) {
M3 m = new M3();
m.pa();
m.pb();
M3 m3 = new M3(3);
m3.pa();
}
}
class M3 {
int n = 5;
int m = 10;
public M3() {
n = 100;
m = 200;
}
public M3(int n) {
this.n = n;
}
public void pa() {
for (int i = 0; i < n; i++) {
System.out.print("*");
}
System.out.println();
}
public void pb() {
for (int i = 0; i < m; i++) {
System.out.print("*");
}
System.out.println();
}
}
运行结果:
****************************************************************************************************
********************************************************************************************************************************************************************************************************
***
第一题:
public class C {
public int x = 100;
public void disp(){
System.out.println(x);
}
public static void main(String args[]){
new C().disp();
new D().dispC();
new D().dispD();
}
}
class D extends C{
private int x = 99;
public void dispD(){
System.out.println(this.x);
}
public void dispC(){
System.out.println(super.x);
}
}
第二题:
接口:
public interface Draw {
/**
* 计算周长
* side 边长
*/
public void calGirth(int side);
/**
* 计算面积
* side 边长
*/
public void calSize(int side);
}
实现:
public class DrawImpl implements Draw{
public void calGirth(int side) {
System.out.println("周长为:" + 4*side);
}
public void calSize(int side) {
System.out.println("面积为:" + side*side);
}
public static void main(String args[]){
new DrawImpl().calGirth(5);
new DrawImpl().calSize(5);
}
}
oh my god!