Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


santhiya
javacode
1 Answer(s)      4 years and a month ago
Posted in : Java Beginners


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

Advertisement
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:
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
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
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
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
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
JSP-EL - JSP-Servlet
} -------------------------------------- JavaBeans.java package javacode; public class JavaBeans
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
servlets - Servlet Interview Questions
javacode; import... package javacode; import javax.servlet.*; import javax.servlet.http.
Computer - JSP-Interview Questions
for this   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
JSP-EL - JSP-Servlet
package javacode; public class JavaBeans{ private String name
java - JSP-Servlet
. --------------------------------------------- Here is the simple code. package javacode; import java.io.*; import
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
JSP-EL - JSP-Servlet
} -------------------------------------- JavaBeans.java package javacode; public
JSP-EL - JSP-Servlet
package javacode; public class JavaBeans{ private String name=""; public
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.
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
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
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
Problem in Servlet - Servlet Interview Questions
error.  Hi friend, package javacode; import java.io.*; import...); } } -------------------------------  package javacode; import javax.servlet.
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 ..I am Sakthi.. - Java Beginners
;Hi friend, package javacode; import javax.swing.*; import
dynamic drop down list box - Java Beginners
;servlets code package javacode; import java.io.*; import javax.servlet.
jsp/servlet - JSP-Servlet
javacode; import java.io.*; import java.io.PrintWriter; import java.sql.
Refresh code - Java Server Faces Questions
----   servlets code package javacode; import
 

 

 

DMCA.com