JAva無視しやすい点
2586 ワード
switchキーワード
switchキーワードの使用では、式のタイプはbyte、short、char、intの4つしかありません.条件が終わるたびにbreakキーワードを追加し、よく使われる使い方:
switchキーワードの使用では、式のタイプはbyte、short、char、intの4つしかありません.条件が終わるたびにbreakキーワードを追加し、よく使われる使い方:
public class demo15
{
public static void main(String args[]){
int j=2;
switch(j){
case 2:
System.out.println("Value is two.");
break;
case 3:
System.out.println("Value is two.");
break;
default:
System.out.println("Value is "+j);
break;
}
}
}
Value is two. :
public class demo15
{
public static void main(String args[]){
int j=2;
switch(j){
case 2:
System.out.println("Value is two.");
//break;
case 3:
System.out.println("Value is three.");
break;
default:
System.out.println("Value is "+j);
break;
}
}
}
Value is twoが されます. Value is three.
のコードを してください.public class demo15
{
public static void main(String args[]){
int j=2;
switch(j){
case 2:
System.out.println("Value is two.");
//break;
case 3:
System.out.println("Value is three.");
//break;
default:
System.out.println("Value is "+j);
//break;
}
}
}
プログラム :Value is two. Value is three. Value is 2
、javaにおけるswitch は、breakに していない り、 が しているかどうかにかかわらず され、breakに するまでプログラムは しない.
, , , :
class A
{
int i=1;
public void fun(){
System.out.println("A-->fun() ");
};
public void fun1(){
System.out.println("A-->fun1() ");
}
}
class B extends A
{
int i=2;
public void fun(){
System.out.println("B--fun() ");
}
}
public class NumberFormatDemo02
{
public static void main(String args[]){
A a=new B();
a.fun(); // fun()
System.out.println(a.i); // A i
B b=new B();
b.fun1(); // B ,
}
}