javacode

javacode

how to use inherritance using switch case.if suppose i use two classes named customer details and student details and i want to call either one at a time so how to use switch case in these type of situation.
help me out please
View Answers

September 2, 2010 at 12:34 PM

I am trying to answer you....

class Person{ //this is the base class
String name;
String type;
public Person(String name,String type){
this.name=name;
this.type=type;
}
public String getType(){
return this.type;
}
}

class Customer extends Person{ //first derived class
public Customer(String name){
super(name,"customer");
}
}

class Student extends Person{ //second derived class
public Student (String name){
super(name,"student");
}
}

class Test{

private Person getInstance(String name,String type){
Person person;
switch(type){
case("customer"): person=new Customer(name);
break;
case("student"): person=new Student(name);
break;
}
return person;
}
public static void main(String args[]){

}
}




Now call the method getInstance() and on the returned object call the method getType().U will get the type of object returned...









Related Tutorials/Questions & Answers:
javacode - Java Beginners
usb detection
usb detection  i want to detect usb device using javacode
Advertisements
hai - Java Beginners
(file[0].getAbsoluteFile()); javacode......... } Error
struts - Struts
to write and how to get the attributes from java(means how to write javacode
struts - Struts
to write and how to get the attributes from java(means how to write javacode
java - SQL
javacode; import java.sql.*; import java.io.*; public class InsertImage... = con.createStatement(); File imgfile = new File("javacode/rose.jpg
java - JDBC
. package javacode; import java.sql.*; import java.sql.Connection; import... res = null; StringBuffer query=null; String filename = "javacode/rose.jpg... FileOutputStream("javacode/rose.jpg"); byte b[]= new byte[size]; x.read(b
Exception: java.lang.IllegalStateException: getWriter() has already been called for this response - JSP-Servlet
, package javacode; import java.sql.*; import java.sql.Connection; import...; ResultSet res = null; StringBuffer query=null; String filename = "javacode...(); OutputStream out=new FileOutputStream("javacode/rose.jpg"); byte b[]= new byte[size
JAVA(JDBC) - JDBC
javacode; import java.sql.*; import java.sql.Connection; import... = null; StringBuffer query=null; String filename = "javacode/rose.jpg... FileOutputStream("javacode/rose.jpg"); byte b[]= new byte[size]; x.read(b
Session Tracking in servlet - Servlet Interview Questions
rewritting: package javacode; import javax.servlet.*; import... -----------------------------------------------  Hidden Form Fields: package javacode; import java.io....   Cookies: package javacode; import java.io.*; import
JSP-EL - JSP-Servlet
} -------------------------------------- JavaBeans.java package javacode; public class JavaBeans
thumbnails - JSP-Servlet
thumbnails  how to create thumbnails using servlets?  Hi friend, package javacode; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.awt.*; import
Computer - JSP-Interview Questions
for this   hi friend, package javacode; import java.io....); } } } ------------------------------------------------- package javacode; import
servlets - Servlet Interview Questions
javacode; import... package javacode; import javax.servlet.*; import javax.servlet.http.
Session ID - Java Beginners
Session ID  Do we get new session id for a new domain after clicking a page link.  Hi friend, package javacode; import java.io....); } } ----------------------------------------------------   package javacode; import
store the image in the oracle using blob and get it back - JDBC
jdbc connection, package javacode; import java.sql.*; import java.io....("javacode/rose.jpg"); FileInputStream fin = new FileInputStream(imgfile... image code package javacode; import java.sql.*; import java.sql.Connection
java - JDBC
java  How to insert and retrieve image from oracle database? PLZ,,,explain with an example code? help,me plz....  Hi friend, package javacode; import java.io.*; import java.io.File; import
servlets - JSP-Servlet
servlets  How would you set an error message in the servlet,and send the user back to the JSP page?Please give java or pseudo code examples.   Hi package javacode; import java.io.*; import javax.servlet.
JSP-EL - JSP-Servlet
package javacode; public class JavaBeans{ private String name=""; public
JSP-EL - JSP-Servlet
} -------------------------------------- JavaBeans.java package javacode; public
java - Java Beginners
java  hello,i work on one project automated placement cell and i need to view and print the resume of student/employee in pdf format .i need a help how to generate .pdf file format using javacode...its a window based application
java - JSP-Servlet
. --------------------------------------------- Here is the simple code. package javacode; import java.io.*; import
JSP-EL - JSP-Servlet
package javacode; public class JavaBeans{ private String name
Insert Image in DB through Servlet - JSP-Servlet
Thanks Rajanikant Hi vijay, This is Servlet code: package javacode...; StringBuffer query=null; String filename = "javacode/rose.jpg"; String...=x.available(); OutputStream out=new FileOutputStream("javacode/rose.jpg"); byte b
Insert Image In DB through Servlet - JSP-Servlet
: package javacode; import java.sql.*; import java.sql.Connection; import...; ResultSet res = null; StringBuffer query=null; String filename = "javacode/rose.jpg...=new FileOutputStream("javacode/rose.jpg"); byte b[]= new byte[size
Problem in Servlet - Servlet Interview Questions
error.  Hi friend, package javacode; import java.io.*; import...); } } -------------------------------  package javacode; import javax.servlet.
servlets - JSP-Servlet
is as follows: package javacode; import java.io.*; import java.sql.
servlets - Servlet Interview Questions
;package javacode; import java.io.*; import javax.servlet.*; import
servlets - JSP-Servlet
;This is servlets code. package javacode; import java.io.*; import java.sql.
how to create a dynamic website - Servlet Interview Questions
; This is Action code. package javacode; import java.io.
java - JDBC
java  i need output as tablename;coloumn1;coloumn2,;coloumn3,fieldvalue1,fieldvalue2,and so on. please tel me the javacode for this using resultset metadata  Hi friend, 1. First import the java packages
currency - Java Beginners
currency  helo guys can you share me a "JAVAcode" about Currency Conversion.Money will convert according to the type of currency.would you help me please... 1 dollar=1.4054 Swiss francs 1 dollar=0.9553 Euro dollars 1 dollar
tomcat - Java Beginners
tomcat  plz tell me about tomcat.working of it .how we deploy a servlet on it.tell me all the things asap. thanks   Hi Sanjay, package javacode; import java.io.*; import javax.servlet.*; import
Source Code for Implementing Search Feature in JSF/JSP using Servlet - Java Beginners
, example in jsf, jsp, java method   Hi friend, package javacode
java - Servlet Interview Questions
java  can u tell me how to connect the database to the servlet in the general java file. let me know the steps for configuring the tomcat server on my computer  Hi package javacode; import java.io.*; import
servlets deploying - Java Beginners
servlets deploying  how to deploy the servlets using tomcat?can you please explain the total deploying and executing process?  Hi friend, package javacode; import java.io.*; import javax.servlet.*; import
call from java - JavaMail
javacode; import java.io.*; import javax.servlet.*; import javax.servlet.http.
jsp - JSP-Servlet
...   Hi friend, package javacode; import java.io.*; import
Dynamic loading of Combo box list using servlet - JSP-Servlet
----   package javacode
code for JSP and Servlet - JSP-Servlet
code for JSP and Servlet  i have to create a jsp page that contains username and password, so how to code servlet according to it?  Hi sushil, package javacode; import java.io.*; import javax.servlet.*; import
Refresh code - Java Server Faces Questions
----   servlets code package javacode; import
unable to compile class file - JSP-Servlet
; servlets code package javacode; import java.io.*; import
jsp/servlet - JSP-Servlet
javacode; import java.io.*; import java.io.PrintWriter; import java.sql.
dynamic drop down list box - Java Beginners
;servlets code package javacode; import java.io.*; import javax.servlet.
Hi ..I am Sakthi.. - Java Beginners
;Hi friend, package javacode; import javax.swing.*; import
web-design - JSP-Servlet
web-design  hi, i wanted to know what is web design.. is it the servlet that we write producing the output on the web page????????  Hi package javacode; import java.io.*; import javax.servlet.*; import
Hi da SAKTHI ..check thiz - Java Beginners
to do please explain in detail. package javacode; import java.lang.*; import... ImageIcon("/home/vinod/workspace/CodeDevelopment/javacode/images.jpg"); img2
How display a image on servlet from file upload - JSP-Servlet
. package javacode; import java.sql.*; import java.io.*; import....jar and set that on classpath.I keep the servlet file in javacode package. First
jdbc - JDBC
){ e.printStackTrace(); } } }  Hi, package javacode; import java.sql.
jdbc mysqll - JDBC
. package javacode; import java.sql.*; public class DisplayTablename

Ads