Java: Object-oriented (Leak filling)

Source: Internet
Author: User

1. The modifier for a class can only be: public, default. In addition: final, Abstract,public interface (interface before the public will be an error).

2. When creating an object in the main function, the non-parametric construction of the new class is the parameterless construct of which class, and the non-parametric construction of the class's parent is implicitly invoked.

New has a parameter structure, and it implicitly calls the non-parametric construct of the class parent class.

3. Both the construction method and the normal method can be decorated with four modifiers: public,private,protected, default.

Additionally: Static can also be used, but the construction method does not return a value.

The parent class construction method and the parent class private property cannot be inherited by the quilt class, but can be called through the Super Quilt class.

  

eg

 Public classTest { Public Static intAge ; protectedTest () {System. out. println ("Ancient Road, west of Thin horse"); }    protectedTest (intAge ) {         This. age=Age ; System. out. println ("old tree with withered vines and faint raven"); }         Public Static voidMain (string[] args) {Test T=NewTest (); Test TT=NewTest ( -); Test2 TT2=NewTest2 (); Test2 T2=NewTest2 ( -, About); /** The old road West thin horse * withered ivy tree Faint crow * withered vine old tree faint crow * heartbroken people in the Tianya * withered vine old tree faint crow * Small bridge water Family*/    }}classTest2 extends test{Private intscore;  PublicTest2 () {Super (2);//equivalent to the display calling the parent class has a parameter constructSystem. out. println ("the heartbroken man in the horizon"); }         PublicTest2 (intAgeintscore) {Super (1);  This. score=score; System. out. println ("Small Bridge Water family"); }    }

4. Subclasses override methods of the parent class, and the modifier scope should be larger than the parent class.

5. The super and this keyword cannot be used in a static method and will be an error. (Static methods are subordinate to classes, and are produced earlier as classes are loaded, and super and this are all subordinate to objects, resulting in a later generation of objects, with different build times, so the static decorated method is likely to invoke the wrong object that was not created)

What packages are in the 6.package package:

* Common packages in Java: Classes under packages other than the Java.lang package, which require a guide package when used.
* Java.lang Package: Java Core class library, String,system,math ... The classes under this package can be used directly without the need for a guide package.
* Java.util Package: Tool class. Arrays,scanner ...
* Java.io Package: I (input)/O (output) and Java stream input and output related class libraries.
* Java.net Package: A class library related to network programming.
* Java.sql Package: A class library related to database operations.
* Java.text Package: internationalized or formatted output-related class library.
* Java.awt Package/javax.swing Package: graphical interface-related class library
* Declaration package: The first line of the class must be placed using the Packages keyword.
* Syntax: package name; EG:CN.ZZSXT.OOP7;

Methods in the 7.java.lang.object class:

8.toString () returns the string representation of the object. If System.out.println (Stu) is used, the default call Stu.tostring ()
* [email protected]==)
* Cn.zzsxt.oop6.Student (package name, class name) [email protected]+16 binary representation of hashcode code
* The ToString () method is often overridden in subclasses.

import java.util.Arrays; Public classtesttostring { PublicString name="Kuangzhisen"; String []num={"saaaa","sssss","dddd"}; /*@Override public String toString () {return "testtostring [num=" + arrays.tostring (num) + "]"; }*/     Public Static voidMain (string[] args) {intA; Testtostring T=Newtesttostring (); Testtostring TT=Newtesttostring (); System. out. println (t); System. out. println (TT); /** [Email protected] * [email protected]*/        }}

Java: Object-oriented (Leak filling)

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.