The following is a java4android video tutorial from marschen.
Main content of this set.
1. Access Permissions and inheritance.
2. Protected permission
Package COM. marsdroid; // if the child class and the parent class are not in the same package, the Child class cannot inherit the default permission of the parent class. // member variables and member functions. (problematic) // if the child class and the parent class are not in the same package, the Child class can inherit the member variables with the default permission in the parent class. // and the member functions, however, permissions are insufficient and cannot be used. // If the subclass and parent class are in the same package, // student // void introduce () {// system. out. println ("My name is" + name ", my age is" + age); //} // executable // defines public, you can access the/protected permission across packages. The permission is the same as that of default, but protected can only modify member variables and member functions. // But default can modify the class. // use member variables and functions for the protected cross-package. public> protected> default> privatepublic class person {public string name; // you can access protected int age across packages. // you can only access the cross-package of the quilt class. // example: in the program, it can only be accessed by the student subclass. Age // cannot be accessed by the class test. because it is not a subclass of // person, there is no relationship between person and test. // If the variable is declared as private, the variable can only be used in this class. void eat () {system. out. println ("eat");} void sleep () {system. out. println ("Sleep ");}}
Package Org. marsdroid; import COM. marsdroid. person; class student extends person {void introduce () {system. out. println ("My name is" + name + ", my age is" + age );}}
package org.marsdroid;import com.marsdroid.Person;class Test{public static void main(String args[]){Person p = new Person();p.name = "zhangsan";p.age = 10;}}