其他分享
首页 > 其他分享> > 第五周学习总结

第五周学习总结

作者:互联网

一、static-静态常量

(一) 静态变量

 1 public class Student{
 2 private  String name;
 3 private  int age;
 4 private  String gender;
 5 public   static StringteacherName;
 6 publicStudent(){
 7 publicStudent(String name, int age,String gender) {
 8 this.name = name;
 9 this.age =age;
10 thisgender = gender;
11 }
12 public void study(){
13 System.out.printin(name+“正在学习”);
14 }
15 public void show(){
16 System.out.println(name+”,” + jage + ",” +gender);
17 }
18 
19 }
20 public class StudentTest
21 public  static void main(String[] args) {
22 student.teacherNome ="阿邱老帅";
23 //1.创建第一个学生对象
24 Students1 = new Student();
25 s1.setName(“张二");
26 s1.setAge(23);
27 s1.setGender("男");
28 s1.study();
29 s1.show();
30 Student s2 = new Student();
31 s2,setName("李川");
32 s2.setAge(24);
33 s2.setGender("");
34 s2.study();
35 s2.show();
36 }
37 }

 

(二)静态方法

 1 public  classArrayUtil {
 2 private ArrayUtil  () { }
 3 public  static StrinE print (int[] arr)
 4 stringBuilder sb = newStringBuilder();
 5 sb.append("[")
 6 for (int i= 0; i < arr.length;i++){
 7 if(i == arr.length -1){
 8 sb,append(arr[i]);
 9 }else{
10 sb.append(arr[i]).append(", );
11 }
12 }
13 sb.append("]");
14 return sb.tostring();
15 }
16 public static double getAveraga(double[] arr){
17 double sum = 0;
18 for (int i = 0; i  < arr.length;i++)
19 sum=Sum + arr[i];
20 return sum /arr.length:
21 }
22 }
23 publlc class TestDemo{
24 public static void main(String[] args ) {
25 int[] arr1 =(1,2, 3, 4, S1;
26 String str =ArrayUtil.printArr(arr1);
27 System.out.println(str);
28 double[] arr2 = (1.5, 3.7, 4.9, 5.8, 6.6);
29 double avg =ArrayUtil.getAverage(arr2);
30 System.out.println(avg);
31 }
32 }

(三)、static 注意事项

二、继承

(一)、继承定义

(二)、Java继承的特点

(三)继承范围]

(四)成员变量访问特点

 

 1 public static void main(String[] args){
 2 Zi z = new zi();
 3 z, show( );
 4 class Fu {
 5 String name = "Fu";
 6 String hobby = "喝茶”
 7 }
 8 class Zi extends Fu {
 9 String name ="Zi";
10 Stringgame =“吃鸡";
11 public  vold show() {
12 //打印子类
13 //System,outpr 1n(name);//Zi
14 //System.out.print1n(this.name);
15 //System.out.print1n(super.name);
16 //打印父类
17 //System.out.println( hobby);
18 }
19 }

(五)访问成员方法特点

 1 public class Test {
 2 public statlc vold main(Stringl] args) {
 3 Student s = new Student();
 4 s.lunch();
 5 }
 6 class Person {
 7 public void eat() {
 8 System.out.println(吃米饭, 吃菜”);
 9 }
10 public void drink() {
11 System.out.println("喝开水”);
12 }
13 class Student extends Person {
14 public void lunch(){
15 eat();
16 drink();
17 }
18 }
19 class Student extends Perso {
20 public void lunch() {
21 //先在本类中查看eat和drink方法,子类如果没有,就会调用从父中继承下来的eat和drink方法
22 this.eat();
23 this.drink();
24 //直接调父的
25 super.eat(); 
26 super.drink();
27 }

 

(七)继承中的构造方法

 

 

预计下周学习: 多态,抽象类

 

标签:总结,arr,String,void,System,学习,第五,public,name
来源: https://www.cnblogs.com/fan-wang/p/16535912.html