Java can cause memory leaks, polymorphism, garbage collection, clone

Source: Internet
Author: User

, such as an integer large enough to subtract a negative number large enough, results in an overflow. Causes a memory leak.

What is the mechanism for implementing polymorphism in Java?

The method has the same name, and the method has a different number of arguments or types. Java garbage collection is primarily a garbage collection of dynamic memory, typically when the memory is not enough to be garbage collected, or through System.GC () to notify the system for garbage collection. But it does not necessarily guarantee execution.

A static variable can only be a static method to call him.

Super.clone (), which is the default behavior of the Clone () method, because the members in the parent class are first copied before they can be copied.

One of the advantages of the Java language is that it cancels the concept of pointers, but it also causes many programmers to ignore the differences between objects and references in programming, especially the programmers who learn C and C + + after java. And since Java cannot solve the problem of object duplication by simply assigning values, it is often used in the development process to replicate objects using the Clone () method. For example, when a function parameter type is a custom class, it is a reference pass instead of a value pass. Here is a small example:

  1. Public class A implements Cloneable {
  2. Public String name;
  3. Public Object Clone () {
  4. A o = null;
  5. try {
  6. o = (A) super.clone ();
  7. } catch (Clonenotsupportedexception e) {
  8. E.printstacktrace ();
  9. }
  10. return o;
  11. }
  12. }
    1. A a1=new A ();
    2. A a2=new A ();
    3. A1.name="A1";
    4. A2=A1;
    5. A2.name="A2";
    6. System.out.println ("a1.name=" +a1.name);
    7. System.out.println ("a2.name=" +a2.name);

Java can cause memory leaks, polymorphism, garbage collection, clone

Related Article

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.