Personal views of Java and c++&c language----similarities and differences (A)

Source: Internet
Author: User

Date: 2018.7.30

Monday

Blog period: 004

The fourth issue of the blog I would like to think about Java and its similarities and differences with C + +!

  

  Say the difference first! Java is supposed to be more object-oriented, and its Java package class can refer to all class p in the entire file by declaring the Java package file with import, whereas C + + and C (hereafter referred to as c&c++) use the #include< header file > or # Include "header files" to introduce header files, c&c++ classes can also be written as. h files or. cpp (. C) files, as well as a. h file and a standard version of a. cpp file, while a Java package has many. Java class files, which is quite different. Let me say the Java class declaration, which is declared by this class, is the same as our C + + is the same point? C + + in the use of classes, you do not need to declare what this class is a property, that is, protection, private, public, three, because C + + does not have to say this class let it have what kind of property ah, C + + is used in the inheritance of the use of public inheritance, Private inheritance and the inheritance of the protection of inheritance to determine the relationship between your parent class and the subclass, and we java inside it? The class itself is going to have this property! Add its properties to the front of the class, like this: public class test{}.......emmmm ..... In Java, the relationship between the parent class and the subclass is more complex, in fact, it is not complex to say complex! This is the relationship, to understand is to use extends declaration on it! The properties of its class also determine its "inheritance" (because Java does not have this concept, so it is the quotation marks), and C + + you can inherit more than one at a time, leading to single inheritance, multiple inheritance, multiple inheritance, ambiguity and other concepts! And Java is not the same. Java can not be multiple inheritance, but can be single-inheritance and multiple inheritance! For the public, private, protection of these three attributes and "declaration symbol", Java and c&c++, do not say no matter! And then there's the inner member! In Java, each member declares its properties, and C + + is protected: then a whole bunch of members ... private: Then a bunch of members ... public: .... Maybe it's a Java program. I still write very little about it, at this point I still like c++! When the parent and child classes have a member function with the same name, if you write the same format, but the content is different, and there is no special declaration of C + + program! Then wait for the bug (Error)! Our Java introduced a new concept---rewrite (in C + + there is an overlay function inside the outside), and this can be distinguished by super and this, in C + + processing on the trouble, to be the type of the non-inherited time to declare it! If the static type is simple: father::test ();//Row parent class function .... Son::test ();//execute Sub-class function ... As for the virtual function section, such as:

They are one by one corresponding relationships! After all, it takes a long time for you to understand C + + and Java! By the time I send some papers to my blog everyone will be clear! Say the main function again! Difference... It's too big! C is only one main function, Java is a maximum of only one main function in each class! Write up ... Let me give you an example:

= = = as follows for C language implementation

#include <stdio.h>

int main ()

{

printf ("Hello world!\n");
return 0;
}

= = = is implemented as C + +

#include <iostream>

using namespace Std;

int main ()

{

cout<< "Hello world!" <<endl;
return 0;
}

= = = The Java implementation is as follows

public class Test () {

public void static Main (String args []) {

System.out.println ("Hello world!");

}

}

The difference is very big! C++-->java,bool-->boolean, there's one more byte!. This is a small amount of memory in the comparison hour! There are many ways to use arrays in the FOR loop! There are also enumerations ... I'm not introducing it! Let's do it first!

Java and C++&c language personal views----similarities and differences (A)

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.