Java Learning II (object-oriented) day03

Source: Internet
Author: User

Day03

1. Array of reference types
1) First declaration and then assign value
student[] Stus = new Studenr[3];
Stus[0] = new Student ("Zhangsan", +, "LF");
stus[1] = new Student ("Lisi", +, "JMS");
stus[2] = new Student ("Wangwu", "SD");
stus[1].age = 36;//assigns the age of the 2nd element in the Stus to a value of
2) Simultaneous assignment of declarations
student[] Stus = new studenr[]{
new Student ("Zhangsan", +, "LF"),
New Student ("Lisi", "$", "JMS"),
new Student ("Wangwu", "SD")
};
3) Array of array------------array of type int[]
int[][] arr = new int[3][];
arr[0] = new int[2];
arr[0] = new int[2];
arr[0] = new int[2];
A[1][0] = 100;//assigns the 1th element of the 2nd element in arr to a value of
4) iterating through an array of arrays
int[][] arr = new Int[3][4];
for (int i = 0;i<arr.length;i++) {
For (j = 0;j<arr[i].length;j++) {
A[i][j] = +;
}
}

//reference type Array test class Public classStutest { Public Static voidMain (string[] args) {stu[] Stus=Newstu[3];//creating an Stu Array objectstus[0] =NewStu ("Zhangsan", -,"LF");//Create a Stu objectstus[1] =NewStu ("Lisi", -,"JMS"); stus[2] =NewStu ("Wangwu", -,"SD"); System. out. println (stus[1].age);// -         for(intI=0; i<stus.length;i++) {System. out. println (Stus[i].name);        Stus[i].sayhi (); } stu[] SS=Newstu[]{NewStu ("Zhangsan", -,"LF"),            NewStu ("Lisi", -,"JMS"),            NewStu ("Wangwu", -,"SD")        }; int[] arr =New int[3][]; arr[0] =New int[2]; arr[1] =New int[3]; arr[2] =New int[2]; arr[1][0] = -; int[][] as=New int[3][4];  for(intI=0;i< as. length;i++){             for(intj=0;j< as[i].length;j++){                 asI [j] = -; }        }            }}

2. Inherit
1) Role: Code reuse
2" to implement inheritance by extends
3) Superclass/Parent class: Properties and behaviors common to all derived classes
Span style= "font-size:16px" > Derived classes/subclasses: properties and behaviors specific to derived classes
4) when a derived class inherits a superclass, the derived class has the following: Superclass +    Derived class
5) A superclass can have more than one derived class
A derived class can have only one superclass-----------single inheritance

7) Java rule: You must construct a superclass before you construct a derived class

-----The default super () Call the parameterless construction method of the superclass

-----is no longer provided by default
Super () call the superclass constructor method must be placed at the top

3.super: A superclass object that refers to the current object
How to use Super:
1) Super. Member Variable name------------------access a member variable of a superclass
2) Super. Method Name------------------------method for calling a superclass
3) Super ()--------------------------------Call the construction method of the Super class

//the Super Demo Public classSuperdemo { Public Static voidMain (string[] args) {Boo o=NewBoo (); }}classcoo{Coo (inta) {    }}classDoo extends coo{Doo () {Super (5); }    /*//The following code, write does not write all have Doo () {super (); }    */}classaoo{Aoo () {System. out. println ("the construction method of super class"); }}classBoo extends aoo{Boo () {//super ();//default (constructor method for calling superclass)System. out. println ("How to construct a derived class"); }}

Java Learning II (object-oriented) day03

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.