The use of internal classes and the implementation of abstract classes __java

Source: Internet
Author: User
 
Package zhj_test;
		public class Point {public Point () {//todo} (string Name, string address) {this.aname = name;
	point.aaddress = address;
	Public String toString () {return This.getclass (). GetName () + "[" + getName () + "," + point.aaddress + "]";
	public void SetName (final String name) {this.aname = name;
	Public String GetName () {return aname;
	Private String Aname;
	
	public static String aaddress;
	static {aaddress = "BeiJing";
	} {aname = "ASDFASDFASFADSF";
	public static void print (Object obj) {System.out.println (obj);
		public static void Main (string[] args) {point P = new Point ();
	
		
		Point.print (P);
		Point P1 = new Point ("Yoyo", "Shenyang");
		Point.print (P);
		
		
		Point.print (p1);
		Person[] PS = new person[2];
		Ps[0] = new Manager ("Zhj", "Beijing", "1010", 32);
		
		PS[1] = new Employee ("Test", "Beijing", "1010", 6);
		for (person S:ps) {System.out.println (s.tostring ());The abstract public static class person {public person () {} public person (int age) {Thi
		S.setage (age);
		Public abstract String getName ();
		Public abstract String getaddress ();
		Public abstract String GetCode ();
		
		Public abstract String toString ();
		public int getage () {return age;
		public void Setage (int age) {this.age = age;
		
	private int age; public static class Manager extends person {public Manager () {//todo} public Manager (String name,
			string address, string code, int age) {super.setage (age);
			This.aname = name;
			this.aaddress = address;
		This.acode = code;
		Public String GetName () {return aname;
		Public String getaddress () {return aaddress;
		Public String GetCode () {return acode; Public String toString () {return This.getclass (). GetName () + "[name=" + this.getname () + ", age=" + this.get Age () + ", address=" + This.getaddRess () + ", code=" + this.getcode ();
		Private String Aname;
		Private String aaddress;
	Private String Acode; public static class Employee extends person {public employee () {//todo} public employee (String name
			, string address, string code, int age) {super.setage (age);
			This.aname = name;
			this.aaddress = address;
		This.acode = code;
		Public String GetName () {return aname;
		Public String getaddress () {return aaddress;
		Public String GetCode () {return acode; Public String toString () {return This.getclass (). GetName () + "[name=" + this.getname () + ", age=" + this.getage
		() + ", address=" + this.getaddress () + ", code=" + this.getcode ();
		Private String Aname;
		Private String aaddress;
		
	Private String Acode;
 }

}


Description

The implementation of the 1> inner class is shown in the code above, because in Java, static methods in a class cannot invoke dynamic methods directly. Only the inner class is decorated as a static class (public static * * *), and then the member variable and member method of the class can be called in the static class.


2> abstract class: Keyword abstract (the top of the superclass, and the abstract method in the superclass must contain this keyword),

Way:

Abstract classes: Abstract class * * *.

Abstract method: Public Abstract String * * * * * ...

Subclasses must implement all of the abstract methods.

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.