Code practice advanced Features of--java-6-classes __ajax

Source: Internet
Author: User
Tags static class

Welcome to visit the blog Base Code definition abstract class

Abstract class Fruit {public
    String color;
    Public Fruit () {
        color = ' green ';
    }
}
Defining abstract methods
Abstract class: Fruit abstract Method: Harvest ()
public class Test {public
    static void Main (string[] args) {
        System.out.println (the result of the harvest () method that invokes the Apple class is: "); C9/>apple Apple = new Apple ();
        Apple.harvest ();
        SYSTEM.OUT.PRINTLN (the result of the harvest () method of the Orange class of the Whine is: ");
        Orange orange = new Orange ();
        Orange.harvest ();
    }

Abstract class Fruit {public
    String color;
    Public Fruit () {
        color = "green";
    }
    public abstract void Harvest (); Abstract method
}

class Apple extends Fruit {
    @Override public
    Void Harvest () {
        System.out.println () Apples have been harvested. ");
    }
}
member Inner class
public class Outerclass {
    innerclass in = new Innerclass ();
    public void Ouf () {
        in.inf ();
    }
    Class Innerclass {
        innerclass () {
        } public
        void Inf () {
        }
        int y =  0;
    }
    Public Innerclass doit () {
        in.y = 4;
        return new Innerclass ();
    }

    public static void Main (string[] args) {
        outerclass out = new Outerclass ();
        An object instantiation operation of an inner class must be implemented in a Non-static method in an external class or an external class
        Outerclass.innerclass in = Out.doit ();
        Outerclass.innerclass in2 = Out.new innerclass (); Instantiate inner class object
    }
}
Get references to inner and outer classes
public class Outerclass {
    private int x;
    Private class Inner {
        private int x=9;
        public void doit (int ×) {x
            + +;    Call parameter x
            this.x++;   Call the internal class variable
            outerclass.this.x++;    Calling variable X}} for an external class
Local inner class
public class Selloutclass {
    private String name;
    Public Selloutclass () {
        name = "Apple";
    }
    public void Sell (int price) {
        class apple{
            int innerprice=0;
            public Apple (int price) {
                Innerprice = Price;
            }
            public void Price () {
                System.out.println ("Sales Now" + name);
                SYSTEM.OUT.PRINTLN ("Unit Price:" + Innerprice + "Yuan");
            }
        Apple Apple = new Apple (price);
        Apple.price ();
    }
    public static void Main (string[] args) {
        Selloutclass sample = new Selloutclass ();
        Sample.sell (MB);
    }
Anonymous inner class
public class Outstring {public
    static void Main (string[] args) {
        final String sourcestr = "Jilin Province Tomorrow Technology Co., Ltd.--Programming dictionary 。 ";
        Istringdeal s = new Istringdeal () {//anonymous inner class
            @Override public
            String Filterblankchar () {
                string convertstr = So Urcestr;
                Convertstr = Convertstr.replaceall ("", "");
                return convertstr;
            }
        ;
        System.out.println ("source string:" + sourcestr);
        System.out.println ("converted string:" + S.filterblankchar ());
    }

Interface Istringdeal {public 
    String Filterblankchar ();
}
Static Inner class
public class Staticinnerclass {
    static int x = m;
    Static class Inner {
        static void Doitinner () {
            System.out.println ("Member variable of Outer class" +x);
        }
        public static void Main (string[] args) {
            doitinner ();}}}
Inheritance of inner classes
public class Outputinnerclass extends CLASSA.CLASSB {public
    outputinnerclass (ClassA a) {
        a.super ();
    }
}

class ClassA {
    class ClassB {

    }
}
Instance-static inner class seeking Extremum
public class Test {public static void main (string[] args) {double[] array = new DOUBLE[5];
        for (int i=0; i<array.length; i++) {Array[i] = 100*math.random ();
        } System.out.println ("Source array:");
        for (int i=0; i<array.length; i++) {System.out.print (Array[i] + "");
        } System.out.println ();
        System.out.println ("Maximum:" + maxmin.getresult (array). Getmax ());
    System.out.println ("min.:" + maxmin.getresult (array). Getmin ());
        } class Maxmin {public static class result {private double max;
        Private double min;
            Public result (double max, double min) {This.max = max;
        this.min = min;
        Public double Getmax () {return max;
        Public double getmin () {return min;
        } public static result GetResult (double[] array) {double max = Double.min_value; Double min = Double.
        Max_value;
            for (double i:array) {if (I>max) max = i;
        if (i<min) min = i;
    Return to new result (max, min); }
}

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.