【007】运算符和表达式
Tips:
1、& 和 &&(| 和 ||)
普通逻辑运算下基本相同,不同的是以下:
public class test{
public static void main(String args []){
int i = 5;
int j = 5;
boolean e = i > 6 & i++ >7;
boolean f = j > 6 && j++ >7;
System.out.println(e);
System.out.println(f);
System.out.println(i);
System.out.println(j);
}
}
打印结果为:
false6false5
不同之处:
使用&&的时候,一旦检测出false,则剩余部分不运算
使用&&的时候,一旦检测出false,则剩余部分不运算
2、表达式的类型和表达式的值的数据类型一样
【008~009】分支语句和练习
就是每种程序语言会用到的~
顺序~
if else~
switch case~
很浅的知识点,有基础的基本不用再看[´・ω・`]
Tips:
switch(a){},a的类型只有:char boolean short int
【010~011】循环语句
while
for
略[´・ω・`]
【012】面向对象思维方式
谁来做-怎么做
整体-部分
抽象-具象
其他略[´・ω・`]
【013】类和对象
创建类的方法
class 类名{
属性-描述类的状态;
方法-描述类的行为;
}
如:
class Dog{
char color;
void barking(){
System.out.println("a"+color+"dog is barking~~~");
}
}
创建对象什么的~都懂的~
【015】函数重载和构造函数
Tips:
1、带参数的函数
如
void A(int a){}调用时则为A(10)
2、重载的定义:同一个类中,方法名相同,参数不同
3、构造函数:不算作成员函数。
class Dog(){
Dog(){
//构造函数默认是这样~
//有了构造函数之后编译器不会再添加这种空白构造函数
}
Dog(String c,int a){
//构造函数也能重载哦[´・ω・`]
color = c;
age = a;
}
String color;
int age;
}
Dog d1 = Dog("white",4);
Dog d2 = Dog("black",3);
慢慢找回感觉了-v-
【016】this的使用方法
1、this调用成员变量和方法
class Dog{
String name;
int age;
String color;
Dog(){
System.out.println("barking");
}
Dog(String name,int age){
this(); //相当于System.out.println("barking");
this.name = name;
this.age = age;
System.out.println(name + " is " + age);
}
Dog(String name,int age,String color){
this(name,age); //调用本类中的其他构造函数,一个构造函数中一定只有一次this调用,而且是第一行
this.color = color;
System.out.println(name + " is " + age + " and " +color);
}
}
主函数:
class test{
public static void main(String arg []){
Dog d1 = new Dog();
Dog d2 = new Dog("sam",12);
Dog d3 = new Dog("sam",12,"yellow");
}
}
结果:
【017】static关键字的作用
静态成员变量、静态函数或者静态代码块
1、静态成员变量
所有对象使用的静态成员变量是同一个~内存块是一个
2、静态成员函数
无需生成对象即可调用函数不能使用非静态变量,不能使用this.变量
3、静态代码块
class Dog{
static{
System.out.println("装载类时执行~不需要main主函数");
}
}
【018~019】继承
java只支持单继承。
只继承成员变量和成员函数。
子类构造函数中,必须调用父类的构造函数。
编译器会自动在构造函数首行加上super()以对应父类构造函数(根据super的参数来区别父类的构造函数)
*学过面向对象的对这些应该没难度
*学过面向对象的对这些应该没难度