Solved

Class overwritten?

Posted on 2002-05-11
2
290 Views
Last Modified: 2013-11-23
section A)
Consider the following java classes-
GenericServlet class:
public abstract class GenericServlet extends Object implements Servlet, ServletConfig, Serializable.
HttpServlet class:
public abstract class HttpServlet extends GenericServlet implements Serializable.

section B)
Consider my class below:
public class GenericServlet extends HttpServlet.

It is the base class of HttpServlet class as in section A), however, it is again defined to be a sub-class of HttpServlet in B).
Does B) overwrite a class?
Or B) defines a totally new class only?
How is the GenericServlet be interpreted?
0
Comment
Question by:kenchan2000
2 Comments
 

Expert Comment

by:hogberg78
ID: 7003654
Homework? Think about the packages/namespaces.
0
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
ID: 7003713
 You cannot have two classes of the same name in the same package. What you have written up there could not be compiled if you were to use it with javac. Two classes can have the same name if they reside in different packages. You would have to give the full name of the package. If you have two GenericServlet classes in different packages (package1.GenericServlet and package2.GenericServlet) then you could do something like:

// GenericServlet in package1
package package1;
public abstract class GenericServlet extends Object implements Servlet, ServletConfig, Serializable.

/ HttpServlet in either package2 or somewhere else.
public abstract class HttpServlet extends package1.GenericServlet implements Serializable

and

// Generic Servlet in package2
package package2;
public class GenericServlet extends HttpServlet.

  Hope it helps.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 67
Eclipse IDE - Cannot copy/paste from console output 8 126
simple java question 3 44
tomcat not starting 6 29
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now