Application of abstract classes and interfaces in Java

Source: Internet
Author: User
User. Java package admin; public interface user {public static int dd = 2000; public abstract string GETID (); // Add abstract in the product. Because the default modifier in the interface is abstract public abstract void setid (string ID); public abstract string getname (); public abstract void setname (string name );} /*** this is to define a user interface **. It only defines some basic operation methods and then writes them in the abstract class **/abstractuser. javapackage admin; public class abstractuser Implements user {private string ID; private string name; Public void setid (string ID) {This. id = ID;} Public String GETID () {return this. ID;} public void setname (string name) {This. name = Name;} Public String getname () {return this. name;} public void say () {system. out. println ("this is abstractuser") ;}/ ** this is an abstract class Implements user interface. The abstract class overrides all the methods in the interface, then all attributes of the user object are defined. ***/sqluser. javapackage admin; public class sqluser extends actuser {Public String show () {return "this is sqluser" ;}}/*** This is a class with actual functions, it inherits abstractuser, and the method added in it is only the * unique method **/web related to some special classes. javapackage admin; public class Web {public static void main (string ARGs []) {sqluser user = new sqluser (); abstractuser abuser = new abstractuser (); abuser. say (); system. out. println (user. show (); system. out. println (user. dd) ;}}/** abstract class and interface application ** the interface generally defines general abstract methods. The abstract method is added before the method, because the default modifier of the interface is that abstract * classes with abstract methods must be declared as abstract classes, and classes that inherit abstract classes as subclasses must be overloaded, if there is no abstract method in an abstract class, this class is also * instantiated **. Generally, during project development, the ** interface defines an operation on properties * Get Set * to define properties in the abstract class, override operation ** and inherit the subclass of the abstract class to add some features unique to the current subclass. If there are any new functions in the future, you only need to inherit the abstract class and add some methods. Then you can ******/

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.