Fri Mar 20, 2009 8:17 pm
enum PaymentTypes
{
PREPAID, POSTPAID, NEW
}
public class Main {
public static void main(String[] args) {
PaymentTypes currentPayType=PaymentTypes.NEW;
switch(currentPayType)
{
case PREPAID:
System.out.println("This type is prepaid");
break;
case POSTPAID:
System.out.println("This type is postpaid");
break;
case NEW:
System.out.println("This type is new");
break;
default:
System.out.println("This type is not defined!!");
break;
}
}
}
enum PaymentTypes {
PREPAID, POSTPAID, NEW
}
This type is new
public class Main {
public static void main(String[] args) {
PaymentTypes newpayType=PaymentTypes.NEW;
PaymentTypes prepaidType= PaymentTypes.PREPAID;
if(newpayType.compareTo(prepaidType)==0)
{
System.out.println("The two enum values are equal and of same order");
}else if(newpayType.compareTo(prepaidType)==-1)
{
System.out.println("The two enum variables are different and second parameter is highly ordered");
}else
{
System.out.println("The two enum variables are different and second parameter is less ordered");
}
}
}
enum PaymentTypes {
PREPAID, POSTPAID, NEW
}
The two enum values are different and parameter is less ordered
public enum CarEnum {
BMW("BMW"), TOYOTA("TOYOTA"), FIAT("FIAT");
private String CarType;
private CarEnum(String CarType) {
this.CarType = CarType;
}
public String getCarType() {
return CarType;
}
}
public class EnumTest {
static CarEnum mycar;
public static void main(String args[])
{
System.out.println(mycar.BMW.getCarType());
}
}
public class Main {
public static void main(String[] args) {
// To print all the values of enum type :
for (CarEnum carType : CarEnum.values()) {
System.out.println("Car type:- " + carType);
}
}
}
enum CarEnum {
BMW("BMW"), TOYOTA("TOYOTA"), FIAT("FIAT");
private String CarType;
private CarEnum(String CarType) {
this.CarType = CarType;
}
public String getCarType() {
return CarType;
}
}
public class Main {
public static void main(String[] args) {
System.out.print(CarEnum.valueOf("BMW"));
}
}
enum CarEnum {
BMW("Bavarian Motor Works"),
TOYOTA("Too Often Yankees Overprice This Auto"),
FIAT("Fabbrica Italiana Automobili Torino");
private String CarType;
private CarEnum(String CarType) {
this.CarType = CarType;
}
public String getCarType() {
return CarType;
}
}
BMW
public class Main {
public static void main(String[] args) {
System.out.println(new BillingAccount());
// You can access the enum as class member:
// If private access you can acces it directly as follows:
System.out.println(BillingAccount.PaymentTypes.NEW);
}
}
class BillingAccount {
enum PaymentTypes {
PREPAID, POSTPAID, NEW
}
private String billingNumber;
private String paymentType;
public BillingAccount() {
billingNumber = "32423";// Any Data
paymentType = PaymentTypes.POSTPAID.toString();
}
@Override
public String toString() {
return "paymentType= " + paymentType;
}
}
paymentType= POSTPAID
NEW
public class EnumTest {
enum Food {
BREAD("BREAD"),CHEESE("CHEESE"),MEAT("MEAT");
private String myfood;
Food(String s)
{
myfood = s ;
}
public String getValue()
{
return myfood ;
}
}
public static void main(String args[])
{
System.out.println(Food.BREAD.myfood+" "+Food.BREAD+" "+Food.values());
new EnumTest2();
}
}
class EnumTest2 {
EnumTest2()
{
System.out.println(EnumTest.Food.BREAD);
}
}
BREAD BREAD [LEnumTest$Food;@11b86e7
BREAD
public class Main {
public static void printEnum(CarEnum carEnum)
{
System.out.println(carEnum);
}
public static void main(String[] args) {
printEnum(CarEnum.FIAT);
}
}
enum CarEnum {
BMW("BMW"), TOYOTA("TOYOTA"), FIAT("FIAT");
private String CarType;
private CarEnum(String CarType) {
this.CarType = CarType;
}
public String getCarType() {
return CarType;
}
}
FIAT
enum B
{
}
enum A extends enum B
{
// Define you enum here .
}
interface enuminterface
enum B implements enuminterface
{
}
enum A implements enuminterface
{
// Define you enum here .
}
return type myfunction (enuminterface Enumparam) ;
Wed Mar 29, 2017 3:13 am
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.