Question: javacode

Ads

 
 
 

Share on Google+Share on Google+

santhiya
javacode
1 Answer(s)      6 years and 8 months 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
Ads
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...

Ads









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
Tutorials   
Java Spring Hibernate Struts Training java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile?

Ads

 
Advertisement null

Ads