学过C++面向对象之后其实听这些没什么压力的。类就是类,对象就是对象。通过类来面向对象。类不是对象的集合,而是几个对象有共有属性,才把它们称为一类,但是每个对象除了这些共有属性,还有自己的特别属性,所以不能说类是对象的集合。
2015-11-28
public void show(){}system.out.println("姓名:" + name + ",性别:" + sex + ",年龄:" + age);}
public static void main(String[] args) {
HelloWorld hello = new HelloWorld();
hello.name();
hello.sex();
age();
System.out.println("姓名:"+hello.name+",性别:"+hello.sex+",年龄:"+age);
}}
public static void main(String[] args) {
HelloWorld hello = new HelloWorld();
hello.name();
hello.sex();
age();
System.out.println("姓名:"+hello.name+",性别:"+hello.sex+",年龄:"+age);
}}
2015-11-28
class Circle extends Shape
{
@Override
public void zhouchang() {
// TODO Auto-generated method stub
System.out.println("圆的周长等于 2πr");
}
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("圆的面积等于πr²");
}
}
{
@Override
public void zhouchang() {
// TODO Auto-generated method stub
System.out.println("圆的周长等于 2πr");
}
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("圆的面积等于πr²");
}
}
2015-11-27
class Rectangle extends Shape
{
@Override
public void zhouchang() {
System.out.println("长方形周长等于(长+宽)*2");
}
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("长方形周长等于(长*宽)");
}
{
@Override
public void zhouchang() {
System.out.println("长方形周长等于(长+宽)*2");
}
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("长方形周长等于(长*宽)");
}
2015-11-27
public abstract class Shape {
public abstract void zhouchang();
public abstract void mianji();
}
public abstract void zhouchang();
public abstract void mianji();
}
2015-11-27
if(this == obj){ return true }
if(obj != null && obj.getClass() == this.getClass()){ 当前CLASS c = (当前CLASS)obj; if(this.get属性值.equals(c.get属性值)){ return true } }
return false;
if(obj != null && obj.getClass() == this.getClass()){ 当前CLASS c = (当前CLASS)obj; if(this.get属性值.equals(c.get属性值)){ return true } }
return false;
2015-11-26
public static int sum() {
return(score1+score2);
}
int allScore = sum();
return(score1+score2);
}
int allScore = sum();
2015-11-26