Thread thread = new Thread()
{
public void run()
{
while(true)
{
try
{
Thread.sleep(500);
}
catch(Exception e){}
System.out.println("1:"+this.getName());
System.out.println("2:"+Thread.currentThread().getName());
}
}
};
this problem a long time ago had thought at first to see the definition of an interface , you need to generate interface objects ( perhaps say there is an error generated interface objects , that is, new interfaces ) when the methods of the interface for the definition of the method body .
did feel very strange, because before seen a little bit of C + +, the impression that a class method is fixed, generally not in the definition of the object, and then the methods in the class to be modified. JAVA
but the interface is unique , think this is a new feature .
but just discovered this problem, which makes me very puzzled . The code is as above.
When I was in a class defines an object, I still can not abstract class non-abstract methods overridden .
that such classes and interfaces What's the difference , it is a more advanced interface ,
this class have the same thing only those properties and method names , as methods to complete the function , the programmer can define a class in its own object when modified.
( This is simply like an interface , rather than a class )
A few days ago saw a mention in the forum JAVA multi-state problem, I say without going through the JAVA virtual function , you can complete a subclass of the parent class method to access the operation . The results have a friend that , JAVA , in addition to final and static, all methods are virtual functions.
I did not know whether the object is generated rewrite the above methods.
There , JAVA in what time, the resulting object , you can not modify its corresponding class itself has been defined way to do that ?
------ Solution ------------------------------------ --------
inheritance, anonymous inner classes
------ Solution ------------------------ --------------------
there , JAVA in what time, the resulting object can not be modified which corresponds to the class itself has been defined way to do that ?
The final keyword can be used , and processing private access control , the method before adding final or private
------ Solution ------------ --------------------------------
LZ, you want more, this is the anonymous class only, the final compilation , which is a class.
------ Solution ---------------------------------------- ----
interfaces, abstract classes , polymorphism , java features ah. . . .
When a thing can not or do not want to be another class called by another class called, you can use anonymous inner class friends.
没有评论:
发表评论