如何创建JAVA类,如下?

Python044

如何创建JAVA类,如下?,第1张

1)new--->project--->Java Project -->Project Name 中写工程

2) public class Mammal{

public int weight //类型根据需要定

protected int height

int legs

private int tail

public void printWeight() {

System.out.println(“ The weight is: ”+weight)

}

protected void printHeight() {

System.out.println(“ The heigh tis: ” + height)

}

void printLegs(){

System.out.println(“ The tail tis: ”+ tail)

}

private void printTail(){

System.out.println(“ The legs tis: ”+ legs)

}

}

3) public class Cat extends Mammal{

public void printWeight() {

System.out.println(“ The weight of the cat is: ”+weight)

}

}

哎, 没有动力了, 不想写了, 先给分吧, 有动力再写吧

定义一个类,class A={},然后创建这个类对象,A a = new A()有没有参数看你类定义的构造函数; 例代码如下:

class TestInner{

public static void main(String [] args)

{

Outer outer = new Outer()

Outer.Inner inner = outer.new Inner()

}

}

在内部类(Inner Class),可以随意的访问外部类的成员,这可让我们更好地组织管理我们的代码,增强代码的可读性。