//★只是调了Month(int i)方法, 排行根本就没有变化,
package com.ncs;
public class EnumDemo {
public enum Month{
//不一定对的
JAN,FEB(4),MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC;
//最后最好写 ';' 如果后面有代码 ,一定要';'
//如果没有 可以 省略
//如果要写构造 方法,写在JAN,FEB,MAR,AP..这些的后面
//和自己用 JAVA 类 实现的 一样,只可以让你用 private
private Month(){System.out.println("----Month()------");}
private Month(int i){System.out.println("----------Month(int i)-----------");}
//运行时 可以看见 输出 很多----Month()------
//可以知道 JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC 都是静态变量
//类一到 JVM,静态的东西都会 执行了
//如何指定使用 Month(int i) 呢???
//FEB(4)
//★只是调了Month(int i)方法, 排行根本就没有变化,
}
public static void main(String[] args) {
Month month = Month.SEP;
System.out.println(month); //JDK给实现了toString方法
System.out.println(month.name()); //和上面一样的
System.out.println(month.ordinal());// 排行老几 int 类型 0 开始
System.out.println(month.getClass().getName());
//看看有上面静态方法
System.out.println(Month.valueOf("NOV"));//WEB APP 会用到的
System.out.println(Month.values()); //可以返回一个数组,不可以直接遍历一个枚举类,
//一定要先 返回 一个数组再遍历
//看看数组的长度
System.out.println(Month.values().length);
System.out.println(Month.FEB.ordinal());
}
}
分享到:
相关推荐
introduce in english
Java A Beginner's Guide(6th) 英文无水印pdf 第6版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系...
Java Programming for the Absolute Beginner.pdf
Java A Beginner's Guide(6th) 英文epub 第6版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Java A Beginner's Guide(6th) 英文mobi 第6版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
This book is for anyone who wants to learn computer programming and knows absolutely nothing about it. If you are wondering whether this book is going to teach you how to create amazing applets or ...
Fully updated to cover Java Platform, Standard Edition 7 (Java SE 7), Java: A Beginner's Guide, Fifth Edition starts with the basics, such as how to compile and run a Java program, and then discusses...
Java Programming for the Absolute Beginner
Pentaho 8 Reporting for Java Developers 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Java For Absolute Beginner
java beginner guide,
Java A Beginner’s Guide(7th) 英文epub 第7版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Java A Beginner’s Guide(7th) 英文azw3 第7版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
jQuery for Designers Beginner's Guide Second Edition 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或...
Welcome to C# and the world of Windows, Internet and World-Wide-Web programming with Visual Studio and the .NET platform! This book is the second in our new .NET How to Program series, which presents ...
Python Programming for the Absolute Beginner
Algorithm-Machine-Learning-for-Beginner-by-Python3.zip,斯克莱恩、坦索流。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
Microsoft Excel VBA Programming for the Absolute Beginner 2002
一本适用于java初学者的英文版教材,很全面的介绍了Java的初阶内容。
Python Programming for the Absolute Beginner 3rd 适用于Python 初学者