The difference between throw and throws:::::
Difference Four: The throw statement is used in the body of the method, indicating that the exception is thrown and processed by the statement in the method body
The throws statement is used after the method declaration to indicate that the exception is thrown, and is handled by the statement in the previous-level method that called the method.
Difference Five: throws is basically declaring that this method throws the exception of this type of main, so that other places call it when it knows to catch this exception
Throw is a specific action to throw out an exception, so it is throwing an exception instance
Difference Six: throws indicates which of you may be inclined. These exceptions do not necessarily occur.
Throw it, that's where you turn that tendency into reality. Execution of a throw must throw some kind of exception.
Difference Seven: Throws appears in the method function head, while the throw appears in the function body;
Interface:
Attributes declared in an interface automatically become public static final
The method declared in the interface automatically becomes public
Classes declared in an interface automatically become public static
If you don't need a connection between an inner class object and its enclosing class object, you can declare the inner class as static. This is often referred to as nested classes (nested Class). To understand the meaning of static when applied to inner classes, you must remember that a normal inner class object implicitly holds a reference to the outer class object that created it. However, this is not the case when the inner class is static. A nested class means:
1. To create an object of a nested class, the object of its enclosing class is not required.
2. Non-static perimeter class objects cannot be accessed from objects in the nested class.
public class Z1 {
private static int i = 1;
private int j = 10;
public static void Outer_f1 () {
}
public void Outer_f2 () {
}
Static inner classes can be modified with public,protected,private
Static or non-static members can be defined in a statically internal class
Static Class Inner {
static int inner_i = 100;
int inner_j = 200;
static void Inner_f1 () {
Static inner classes can access only static members of external classes (including static variables and static methods)
System.out.println ("outer.i" + i);
Outer_f1 ();
}
void Inner_f2 () {
Static inner classes cannot access non-static members of external classes (including non-static variables and non-static methods)
System.out.println ("Outer.i" +j);
Outer_f2 ();
SYSTEM.OUT.PRINTLN ("Non-static Method");
}
}
Class Innerz {
int inner_j = 200;
void Inner_f2 () {
Static inner classes cannot access non-static members of external classes (including non-static variables and non-static methods)
System.out.println ("Outer.i" +j);
Outer_f2 ();
SYSTEM.OUT.PRINTLN ("Non-static tired non-static method");
}
}
public void Outer_f3 () {///external class accesses static members of inner classes: inner class. Static members
System.out.println (Inner.inner_i);
Inner.inner_f1 ();
An external class accesses a non-static member of an inner class: instantiates an inner class to
Inner Inner = new Inner ();
Inner.inner_f2 ();
}
public static void Main (string[] args) {
New Z1 (). OUTER_F3 ();
Z1. Inner z=new Z1. Inner ();
Z.inner_f2 ();
Z1 z1=new Z1 ();
Z1. Innerz zz=z1.new Innerz ();
Zz.inner_f2 ();
}
}
Generating a static inner class does not require an external class member: This is the difference between a static inner class and a member inner class. Objects of a static inner class can be generated directly: Outer.Inner in = new Outer.Inner (), rather than generated by generating an external class object. This actually makes the static inner Class A top class (under normal circumstances, you cannot place any code inside the interface, but the nested class can be part of the interface because it is static.) Just place the nested class inside the interface's namespace, which does not violate the rules of the interface)
Java-throw,throws and Internal classes