scjp学习笔记

本文通过几个具体的Java代码示例,展示了如何实现数值运算、数组操作、文件流创建及面向对象编程等基本功能。其中包括计算立方值、初始化数组、使用switch语句进行条件判断以及子类覆盖父类方法的实例。

public static void main( String args[] )

{          int a = 5;

           System.out.println( cube( a ) );

}

static          int cube( int theNum )

{

           return theNum * theNum * theNum;

}

===========================================

          int dayhigh[] = { 24,23,24,25,25,23,21 };

          int[] dayhigh = { 24,23,24,25,25,23,21 };

===================================================

int[]a[] = new int[5][5];

==================================

If val = 1 in the code below:

 

 

switch( val )

{       case 1: System.out.print( "P" ); //break;

        case 2:

        case 3: System.out.print( "Q" );

           break;

        case 4: System.out.print( "R" );

        default: System.out.print( "S" );

} 结果:PQ       有 break;结果:P      若val=100 结果:S

==========================================

the FileOutputStream constructor:

FileOutputStream(FileDescriptor fd)
FileOutputStream(String n, boolean a)
FileOutputStream(File f)

===============================================

 

    class Base {
      public void method(int i) {
        System.out.println("Value is " + i);
      }
    }

    public class Sub extends Base {
      public void method(int j) {
        System.out.println("This value is " + j);
     }
     public void method(String s) {
       System.out.println("I was passed " + s);
     }
     public static void main(String args[]) {
       Base b1 = new Base();
       Base b2 = new Sub();
       b1.method(5);
       b2.method(6);
    }
}
结果:Value is 5
           This value is 6

 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值