2013年9月10日星期二

How to call the parent class that they have been rewritten as a function

The following is the source code , I asked if you are unsure about what might copy and paste

/ / HttpServlet.java

public class HttpServlet {
public void service () {
System.out.println ("HttpServlet.service ()");
doGet ();
}

public void doGet () {
System.out.println ("HttpServlet.doGet ()");
}

}


/ / MyServlet.java

public class MyServlet extends HttpServlet {

public void doGet () {
System.out.println ("MyServlet.doGet ()");
}
}

/ / Test.java

public class Test {
public static void main (String [] args) {
HttpServlet s = new MyServlet ();
s.service ();
}
}

output after running
HttpServlet.service ()
MyServlet.doGet ()

second output shows the call MyServlet the doGet () method , because I also know why
My question is , in this case how can we call the parent class original method, which allows the output is displayed as
HttpServlet.service ()
HttpServlet.doGet ()
------ Solution ------------------------------- -------------
no way ah. .
------ Solution ---------------------------------------- ----
polymorphism, has been rewritten , irreversible it. 1L did not tease you . .
------ For reference only -------------------------------------- -
changed
HttpServlet s=new HttpServlet();

------ For reference only ----------------------------------- ----


....... tease me
There is no other way , I mean what little used in the HttpServlet class methods can make the service () calls itself doGet ()
post title is the parent class how to call himself to be rewritten as a function ah
------ For reference only --------------- ------------------------
definitely starting HttpServlet own objects tune ah
------ For reference only - -------------------------------------


Are you sure java is not any way to achieve my operation?
I have a C + + based on this problem in C + +, is not a problem , thought , it touches me today to see java polymorphism was found that differences between the two a lot, feeling the C + + polymorphism more freely , but really C / free C + + a lot of things very

没有评论:

发表评论