In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to analyze Java object-oriented features and applications, the content is very detailed, interested friends can refer to, I hope to help you.
##Classes and objects
* Object-oriented and Process-oriented
Process-oriented: refers to similar in C language learning, the code written in the main program (main ()) run, very cumbersome.
Object-oriented: First create a class that contains properties (member variables) and methods (member methods) that describe a thing.
Object orientation refers to the description of a thing.
eg: Describe a mobile phone and create a class called phone.
passage ...; public class phone { //Member variables String name; double price; String color; //Member Method call(String name ) game(String playname) }
##Two common methods
* method overload
There are two ways to assign values to member variables after they are declared:
Initialize:
double x;double y;MethodOveringLoading(){ x=1.2; y=0.0;}//Method overloading//You can define member variables as you want MethodOverLoading(double a,double b){ x=a; y=b;}
So why does this concept of method overloading arise?
Because member variables in a class are generally uninitialized, the concept of method overloading arises when programmers want to set them according to the actual problem.
* variable parameter number method
Now let's look at an example of a member method:
public int sum(int a,int b){ return a+b;}
The problem is that when we enter two values, we only sum 2 numbers, and here we can use the variable number of parameters method;
public int sum(int ... arg){ int sum=0; for(int a:arg) { sum+=a; } return sum;}public static void main(String[] args){ System.out,print(sum(1,2,3))//Output result is 6;}
It should be noted here that in general, the parameters entered are of the same type, but different types of parameters can also be entered.
public int sum(double a,int ... arg)//truepublic int sum(double a,int ... arg)//false
* recursive method
The function calls the method of the function.~ I can't think of any good examples for the time being, so I'll add them later.
##Memory allocation during program execution
* Reference to class
* References to classes within the same package
In this case, no class declaration is required;
* References to classes in different packages
Declare the location of the referenced class: import packagename.classname;//package name. class name
* memory allocation
Memory is divided into three regions during program execution,
Stack, Heap, Method Area
At the beginning, the referenced classes are placed in a place called the method area. Of course, not all the classes in the package will be called when the program runs. This requires a place to distinguish those classes that are used and those classes that are not used. This place is the heap, but the heap does not take all the information in the class, but only takes the member variables and member methods in the class. When you enter Phone one=new Phone () in the main function, where one is an object newly created, one receives an address (address information in the heap where the Phone class is located), and you only need to enter one in the later calls.*** Member methods and member variables can be called in a class.
one_dyas
About how to parse Java object-oriented features and applications to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.