Solved

Class overwritten?

Posted on 2002-05-11
2
289 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

758 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

18 Experts available now in Live!

Get 1:1 Help Now