Java Object-oriented advanced-inheritance application----shaping array class, sorting class, inversion class __java

Source: Internet
Author: User

Analysis:


Class array{//representation array private int temp[];	Integer array private int foot;
		Define Add location public Array (int len) {if (len>0) {this.temp = new Int[len]; }else{this.temp = new int[1];//Minimum maintenance space is 1}} public boolean add (int i) {//Add element if (This.foot<this.temp.len
		GTH) {//There is also space this.temp[foot] = I///add element This.foot + +; Modify the foot sign return true;
		}else{return false;
	} public int[] GetArray () {return this.temp;
}
};
	Class Sortarray extends array{//Sort class public Sortarray (int len) {super (LEN);
	Public int[] GetArray () {//Overwrite method Java.util.Arrays.sort (Super.getarray ());//Sort Operation return Super.getarray ();
}
};
	Class Reversearray extends array{/Reverse Operations class public Reversearray (int len) {super (LEN);
		Public int[] GetArray () {int t[] = new Int[super.getarray (). length];//Open up a new array int count = T.length-1;
		for (int x=0; x<t.length;x++) {T[count] = Super.getarray () [x];//array inversion count--;
	} return t;
}
}; public class Arraydemo{public static void Main (String args[]) {//Reversearray a = NULL;//Declare Inverse class object/a = new Reversearray (5);//Open up 5
		Space size Sortarray a = null;
		A = new Sortarray (5);
		System.out.print (A.add) + "T");
		System.out.print (A.add) + "T");
		System.out.print (A.add (2) + "T");
		System.out.print (A.add) + "T");
		System.out.print (A.add (5) + "T");
		System.out.print (A.add (6) + "T");

	Print (A.getarray ());
		public static void print (int i[]) {//Output array content for (int x=0;x<i.length;x++) {System.out.print (I[x] + ","); }
	}
};


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.