class method can be called by all pairs, and can be called with the class name . class method or object name. class Method . Instance methods can only be called with object names. It is important to note, however, that class methods cannot invoke instance variables, because class methods are allocated at the time the class is loaded, and at this point the object
[]) {
Hasstaticmethod.callme (); Do not create object, call static method directly
Hasstaticmethod OA = new Hasstaticmethod (); Create an Object
Oa.callme (); Use object to invoke static method
}
}
The program two times calls the static method, is allowed, the program output is as follows:
This is a static method. This is a static method.
Allowing a static method to be invoked without creating an object is Java, which allows p
Java static methods, static variables generate a unique identity when called, that is, a static seat is given in memory so that it can be found directly at the time of invocation and saves memory. However, if the declared static method, too many static variables, will consume too much memory, it may cause memory overflow.Non-static methods, non-static variables h
For the exchange of two variables, I found four methods, below I use Java to illustrate.1. Use the third variable to exchange values, a simple method.(Code Demo)1 class Testev 2//Create a Class 3 {4 public static void Main (String[]args) 5 {6 int x =5,y=10;//define two variables 7 8
int temp = x; Define the third Temp variable temp and extract the X value 9 x = y;
iterateMediumOrder(BinaryTreeNode node){ if (node == null){ return; } iterateMediumOrder(node.getLeftChild()); operate(node); iterateMediumOrder(node.getRightChild());}Post-post traversalThat is, the root node is traversed after the left and right subtrees:
Sequencing Traversal Zuozi
And then go through the right sub-tree.
Last Access root node
Exit
Code:/** * 后序遍历 * @param node */public void iterateLastOrder(BinaryTreeNode node){ if (node == n
Enum methods in Java ToString and ordinal methods Public enumLanguage {C, Java, PHP;} Public classEnumdemo { Public Static voidMain (String args[]) {//returns the name of this enum constant (String)SYSTEM.OUT.PRINTLN ("Programming in" +language.c.tostring ()); System.out.println ("Programming in" +Language.Java.toStrin
logicSystem.out.println ("Take the chopsticks, find the table, open the food ..."); }}/*** Canteen*/classrestaurant{/*** Meal method, if the customer to inform the waiter your appetite, he will be based on your appetite to give you "sheng" Rice *@paramClient Queuing Customer *@return */ Public voiddozenrice (client client) {Client.templatemethod (); }} Public classTest1 {//Business Processing class, Lao Wang to make dinner Public Static voidMain (string[] args) {Restaurant waiter=Ne
member variables of the outter object.But the main method is that static methods can run without creating objects, Outter objects are not created, and inner can not access member variables of Outter objects even if they are able to create Objects.therefore, You cannot create an object of an inner class in a static method, preventing the inner class object from accessing the member variables of the outer class before the Outer class object is Created.
value:" +val); Passtest PT=Newpasstest (); Pt.changeint (val);//Value PassingSystem.out.println ("After value passed:" +val); Pt.ptvalue=99; System.out.println ("Initial value:" +pt.ptvalue); Pt.changeobject (PT); System.out.println ("After the reference is passed:" +pt.ptvalue); } }The construction method is a special method. Each class in Java has a construction method that initializes an object of the class. The constructor method has th
= And equals () methods in Java, javaequals MethodsJava data types can be divided into two types:1. The basic data type, also known as the original data type. Byte, short, char, int, long, float, double, booleanThe comparison between them applies the double equal sign (=) to compare their values.2. Reference Data Type (class)When they are compared with (=), they compare their storage addresses in the memory
Two methods:
Method 1: Inherit from Thread classMethod 2: implement the runnable interface
Keywords: Synchronized
Each object has an exclusive lock. The exclusive lock only limits the access of the thread to its synchronization method. It does not make sense to the exclusive lock for non-synchronous methods.Synchronized is a method to solve synchronization problems in Java. Synchronized can be us
Java generics have always been a part of my interest, but since I'm talking about generics, I have to mention erasing. Java generics are implemented using erase, and when generics are used, the specific type information is "erased". For example,:listThe generic type parameter will erase to its first boundary, such as list1 PackageCom.test.generic;2 3 Public classErased {4 Private Final intSIZE = 100;5
Qingfeng2017/2/17function; Understand the member methods and construction methods of a classClass Creatways{public static void Main (String args[]) {Person p1 = new Person (23, "armor");System.out.println ("p1.age=" +p1.age);P1.count (2,3);P1.count (3,6); Person p2 = new Person ("Jia Bao");}}Class Person{//attribute: member variableint age;String name;Behavior: Member Methodspublic void count (int num1, int
Java applets-Implementation of abstract methods in interfaces (solving the problem that JAVA cannot inherit more) and java applets
publicinterfaceSing{publicstaticfinalStringeyecolor="black";publicvoidsleep();publicvoidsing();}publicinterfacePrint{publicstaticfinalStringsex="woman";publicvoidprint();publicvoideat();}
P
) {System.out.println (str); }}Scenario two, if we want to precede each line of the output of scene one, add the words "inside Empty is:". If it is implemented as "sample code 1", it will be 100 times more cumbersome.And if we use the "example code 2" above to make changes, it is more convenient. As follows: Packagelesson15; Public classTest3 {/** * @paramargs*/ Public Static voidMain (string[] args) {//=============== Demand 1 Output "I'm Chinese" =================//println ("I am Chine
The difference between static method and instance method is mainly embodied in two aspects:When you call a static method externally, you can use the "class name. Method Name" way, or you can use the "object name. Method Name" way. The instance method is only in the following way. That is, calling a static method eliminates the need to create an object.When a static method accesses members of this class, it only allows access to static members (that is, static member variables and static
write this article to review the Java static block, Main method, building blocks, construction methods of the order of execution, directly run the following code can be at a glance, no more said.
/** * Run the Parent class Main method The order of execution of each block scope: * Static block (and only once)-> Main method-> construction method of building block->/public class Parent {privat
e int age
-bean.tld" from JAR file "file: ***/WEB-INF/lib/struts. jar ": cause: the jar in the Lib folder of the Project is updated, and the servlet is also released at the time of release. jar and jsp-api.jar. Solution: remove the jsp-api.jar to solve this problem. Bytes -----------------------------------------------------------------------------------------------------------------------------Error: Java. Lang. nullpointerexceptionCause: the DaO instance, man
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.