toString(){ return "姓名:" + this.name + ",年龄:" + this.age ; } }public class Test{ public static void main(String args[]){ Person per = new Person("张三",20) ; System.out.println(per); System.out.println(per.toString()) ; } }Run resultsThe ToString method is covered, and the calling method is the content of the overwrite, and the print class name also defau
The difference between Java abstract class and interface1. Abstract class and interface are two mechanisms in the Java language to support the definition of
Super Keyword:When the parent class is overridden, the subclass object cannot access the overridden method of the parent class, and super is to solve the problem:1. Use the Super keyword to access the member variables and member methods of the parent class:Super. Member variablesSuper. Member method ([Parameter 1, ...])2. Use the Super keyword to access the constructor of the parent
abstract method cannot be defined as private, that is, private and abstract cannot be modified simultaneously, and avstract cannot modify the same method with static,final or native at the same time.Abstract classes cannot be instantiated and can only be inherited as parent classes. From a semantic point of view, an abstract
Java interface and abstract class small notes@author IxenosInterface
1. The interface does not have a constructor because the interface is not instantiated2. Anonymous objects if the constructor that uses the
subclass, the other is handed over to the local operating system. If it happens at the same time, it is tantamount to handing over the implementation to the subclass and handing the implementation to the local operating system, who is going to implement the specific method?2, interface is a special kind of abstract class, the method in the
at the definition of Myinvoke:Inner class Myinvoke:invocationhandler { Override Fun Invoke (Proxy:any, Method:method?, Args:array if (method?. Name.equals ("Dofail")) { LOG.I (TAG, "Dofail") }else if (method?). Name.equals ("DOSUCC")) { LOG.I (TAG, "DOSUCC") } }Last run, look at the result:I/testlib:mytest Start executingI/mainactivity:dofailI/mainactivity:dosucc2. Instance
Abstract classes are often used to characterize the abstract concepts we derive in the analysis and design of the problem domain, as an abstraction of a series of concrete concepts that look different, but are essentially the same, and we cannot instantiate them (not get a concrete one) so they are called abstractions. For example: We want to describe "fruit", it is an abstraction, it has quality, volume an
Simply put, classes that use the abstract modifier are abstract classes, and abstract classes can contain no abstract methods (methods that are modified by the abstract), and abstract classes can also include methods and member va
Package A;public interface AAA {public int getmax (); String getmes ();} Package A;import static Java.lang.system.out;public class test implements Aaa{public int Getmax () {int i = 123;return i;} Public String Getmes () {string s = "method implemented in the interface"; return s;} public static void Main (string[] args) {//TODO auto-generated method Stubtest t =
I. The difference between an interface and an abstract classAbstract class defines two methods, the interface can also define two methods, then at the time of definition, is the definition of abstract class or
C # class, interface, structure, abstract class introduction and comparison of abstract and interface,
Classes in c # are the most common ones. In fact, they define a prototype of variables and methods for a certain type of object
abstract class and interface are two mechanisms that support the definition of abstract classes. It is the existence of these two mechanisms that gives Java a powerful object-oriented capability, and the difference is as follows:(1) Same pointA, both are
Document directory
Code for testing
Original post address: http://www.codeproject.com/KB/cs/abstractsvsinterfaces.aspx
Original Author:Rahman Mahmoodi
Translation: 54sunIntroduction | description
I will discuss abstract class and interface through this article and the attached demo program ). These two concepts often confuse beginners of the object-oriented
{
Public override Void Do ()
{
Console. writeline ("go to take money from some fools ");
}
}
Public class killer: person
{
Public override Void Do ()
{
Console. writeline ("go to kill somebody ");
}
}
Class persondo -- test class{Static void main (string [] ARGs)
{
Person cheater = new cheater ();
Cheater. Do ();
Person killer = new killer ();
Killer. Do ();
}}
Abstract class, interface, abstract class Interface
Why use abstract classes:
If the subclass is not correctly rewritten, no prompt is displayed.
Assume that the code of the parent
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.