Solved

Class overwritten?

Posted on 2002-05-11
2
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

726 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