<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    例題分析

    1.
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;

    public class AA extends Applet {
    ? private int count = 0;
    ? private Button
    ??? onOff = new Button("Toggle"),
    ??? start = new Button("Start");
    ? private TextField t = new TextField(10);
    ? private boolean runFlag = true;
    ? public void init() {
    ??? add(t);
    ??? start.addActionListener(new StartL());
    ??? add(start);
    ??? onOff.addActionListener(new OnOffL());
    ??? add(onOff);
    ? }
    ? public void go() {
    ??? while (true) {
    ????? try {
    ??????? Thread.currentThread().sleep(100);
    ????? } catch (InterruptedException e){}
    ????? if(runFlag)
    ??????? t.setText(Integer.toString(count++));
    ??? }
    ? }
    ? class StartL implements ActionListener {
    ??? public void actionPerformed(ActionEvent e) {
    ????? go();
    ??? }
    ? }
    ? class OnOffL implements ActionListener {
    ??? public void actionPerformed(ActionEvent e) {
    ????? runFlag = !runFlag;
    ??? }
    ? }
    ? public static void main(String[] args) {
    ??? AA applet = new AA();
    ??? Frame aFrame = new Frame("AA");
    ??? aFrame.addWindowListener(
    ????? new WindowAdapter() {
    ??????? public void windowClosing(WindowEvent e) {
    ????????? System.exit(0);
    ??????? }
    ????? });
    ??? aFrame.add(applet, BorderLayout.CENTER);
    ??? aFrame.setSize(300,200);
    ??? applet.init();
    ??? applet.start();
    ??? aFrame.setVisible(true);
    ? }
    } ///:~


    2。
    class SuperClass
    {
    ?int a = 3,b = 6;}
    class SubClass extends SuperClass
    {
    //?int a=30,b=20;
    ?int max(){return ((a > b)? a:b);}}
    public class ABC {

    ?public static void main(String[] args) {
    ?SubClass sb = new SubClass();
    ?System.out.println(sb.max());

    ?}

    }


    3.
    ?? interface? Playable?? {
    ?????? void? play();
    ? }
    ??? interface? Bounceable?? {
    ?????? void? play();
    ? }
    ??? interface? Rollable? extends? Playable, Bounceable?? {
    ????? Ball ball? =?? new? Ball( " PingPang " );//interface 里面的變量為public static final
    ? }
    ??? class? Ball? implements? Rollable?? {
    ?????? private? String name;
    ??????? public? String getName()?? {
    ?????????? return? name;
    ????? }
    ??????? public? Ball(String name)?? {
    ????????? this .name? =? name;???????
    ????? }
    ????? public?? void? play()?? {
    //????????? ball? =?? new? Ball( " Football " );
    ????????? System.out.println(ball.getName());
    ????? }
    ? }


    4.
    public class BB {
    ?String a ;
    public BB(String a){
    ?this.a = a;
    ?System.out.println("11");
    }
    ?public static void main(String[] args) {
    ??String s = new String ("Computer");
    ??if(s == "Computer")
    ???System.out.println("Equal A");
    ??if(s.equals("Computer"))
    ???System.out.println("Equal B");
    ??BB b = new BB("aa");
    ??BB c = new BB("aa");
    ??BB d ;
    ??d = c;
    ??
    ??if(b == c)
    ???System.out.println("Equal b=c");
    ??if(b.equals("aa"))
    ???System.out.println("Equal b equals 'aa'");
    ??if(d.equals("aa"))
    ???System.out.println("Equal d equals 'aa'");
    ??if(d.equals(c))
    ???System.out.println("Equal d equals 'c'");
    ??if(d==c)
    ???System.out.println("Equal d equals 'c'");

    ?}

    }


    5.

    interface? A{
    ??? int x = 0;
    ?}
    ?class B{
    ??? int x =1;
    ?}
    ?class C extends B implements A {
    ??? public void pX(){
    //?????? System.out.println(x);//兩個x都匹配,對于父類的變量,可以用super.x來明確,而接口的屬性默認隱含為 public static final.所以可以通過A.x來明確。

    ??? }
    ??? public static void main(String[] args) {
    ?????? new C().pX();
    ??? }
    ?}


    6.
    public class CalC {
    ???? void amethod(){
    ??????? System.out.println("CalC.amethod");
    ????? }
    ????? CalC(){//---------〉3
    ???????? amethod();//----〉4
    ????????? System.out.println("Hu?");
    ???? }
    ???? public static void main(String[] args) {
    ???????? // TODO Auto-generated method stub
    ???????? CalC cc = new CalChild();//--1初始化調用構造方法,向上轉型,調用弗雷構造方法
    ???????? System.out.println("1");
    ???????? cc.amethod();
    ???? }
    ?}
    ?class CalChild extends CalC{
    ??//----2
    ???? void amethod(){//-----5
    ??????? System.out.println("CalChild.amethod");
    ??? }
    ?}


    7.
    class Vehicle{
    ?String str;
    ?public Vehicle(){}
    ?public Vehicle(String s){
    ??
    ?}
    }
    ?public class Car {
    ?String a;
    ? public Car(String a){this.a = a;}
    ?public static void main(String[] args) {
    ?? Vehicle v = new Vehicle("Hello");
    ?? Car a;
    //?? a = "a";
    ??v = new Vehicle ("How are You");
    ??v.str = "How is going";
    ??System.out.println("Greeting is :" + v+"11");
    ?}

    }


    8.
    class? Parent{
    ?private void method1(){
    ??System.out.println("Parent's method1()");
    ?}
    ?public void method2(){
    ??System.out.println("Parent's method2()");
    ??method1();
    ?}
    }
    public class Childe extends Parent {
    ?public void method1(){
    ??System.out.println("Child's method1()");
    ?}
    ?
    ?public static void main(String[] args) {
    ?Parent p = new Childe();
    ?p.method2();

    ?}

    }?????????


    9.
    class?? O?? {??
    ??????? public?? O()?? {??
    ?????????? System.out.println("A's?? c?? is?? here?? ");??
    ????? }??
    ?????? void?? println()? {??
    ?????????? System.out.println("A's?? v?? is?? here?? ");??
    ?????? }??
    ??? }??
    ?class?? P?? extends? O {??
    ?????? public?? P()?? {??
    ?????????? System.out.println("B's?? c?? is?? here?? ");??
    ?????? }??
    ?????? void?? println()? {??
    ?????????? System.out.println("B's?? v?? is?? here?? ");??
    ?????? }??
    ?? }??
    ?? public?? class?? Chp_4_2? {??
    ?????? public?? static?? void?? main(String[]?? args)? {??
    ?????????? O?? b?? =?? new?? P();
    ?????????? b.println();
    ?????? }??
    ? }

    10.
    public class Cwich {

    ?/**
    ? * @param args
    ? */
    ?public static void main(String[] args) {
    ??int x = 9;
    ??switch(x){
    ??default:
    ???System.out.println(1);
    ??case 1:
    ??System.out.println(1);
    ??case 2:
    ??case 3:
    ???System.out.println(3);break;
    ??case 4:
    ???System.out.println("4");
    //??default:
    //???break;
    ??}


    11.
    class Tree{}
    class Pine extends Tree{}
    class Oak extends Tree{}
    public class Forest {

    ?public static void main(String[] args) {
    ??
    ??Tree tree = new Pine();
    ??if(tree instanceof Pine)
    ???System.out.println("Pine");
    ??if(tree instanceof Tree)
    ???System.out.println("Tree");
    ??if(tree instanceof Oak)
    ???System.out.println("Oak");
    ??else
    ???System.out.println("Oops");

    ?}

    }



    12.
    class FuZhia {
    ? private int a;
    ?? public int change(int m) {
    ???? return m;??
    ?? }?
    ???
    ?}
    ?public class FuZhi extends FuZhia{
    ?? public int b;?
    ? public static void main() {
    ?? FuZhi? aa = new FuZhi();
    ?? FuZhia? bb = new FuZhia();
    ??? int k;?
    ??? k=bb.change(30);?
    ?? }
    ?}

    13.
    import java.sql.*;
    public class Jdbc
    {
    String dbUrl="jdbc:oracle:thin:@127.0.0.1:1521:orcl";
    String theUser="admin";
    String thePw="manager";
    Connection c=null;
    Statement conn;
    ResultSet rs=null;
    public Jdbc()
    {
    try{
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    c = DriverManager.getConnection(dbUrl,theUser,thePw);
    conn=c.createStatement();
    }catch(Exception e){
    e.printStackTrace();
    }
    }
    public boolean executeUpdate(String sql)
    {
    try
    {
    conn.executeUpdate(sql);
    return true;
    }
    catch (SQLException e)
    {
    e.printStackTrace();
    return false;
    }
    }
    public ResultSet executeQuery(String sql)
    {
    rs=null;
    try
    {
    rs=conn.executeQuery(sql);
    }
    catch (SQLException e)
    {
    e.printStackTrace();
    }
    return rs;
    }
    public void close()
    {
    try
    {
    conn.close();
    c.close();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    public static void main(String[] args)
    {
    ResultSet rs;
    Jdbc conn = new Jdbc();
    rs=conn.executeQuery("select * from test");
    try{
    while (rs.next())
    {
    System.out.println(rs.getString("id"));
    System.out.println(rs.getString("name"));
    }
    }catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    }

    14.
    class AB {
    ?String s1;
    ?String s2;
    ?AB(String str1,String str2){
    ??s1 = str1;s2 = str2;
    ?}
    ?public String toString(){
    ??return s1+s2;
    ?}
    }
    public class jiahao {
    ?public static void main(String[] args) {
    ??AB s = new AB("Hello!","I love Java.");
    ??System.out.println(s.toString());
    ?}

    }


    15.
    class N{
    ?N(){
    ??System.out.println("Class N Constructor");
    ?}
    }
    public class M extends N{
    ?M(){System.out.println("Class M Constructor");}
    ?
    ?public static void main(String[] args) {
    ??M m = new M();

    ?}

    }


    16.
    ?? class? Base? {
    ???????? private? final? void? f()? {? //注意final
    ?????????? System.out.println( " Base.f() " );
    //?????????? public int i;//局部變量前不能放置任何修飾符
    ?????? }
    ?? }
    ??
    ??? class? Derived? extends? Base? {
    ???????? public? final? void? f()? {?? //注意final
    ????????? System.out.println( " Derived.f() " );
    ????? }
    ? }
    ??
    ??? public?? class? Main?? {
    ??????????? public?? static?? void? main(String[] args)?? {
    ????????? Derived op1? =?? new? Derived();
    ???????? Base op2 = op1;
    ????????? op1.f();
    //???????? op2.f();
    ????? }
    ?}



    17.
    import java.awt.AWTEvent;
    import java.awt.TextArea;
    import java.awt.event.TextEvent;

    public class MyTextArea extends TextArea{
    ?public MyTextArea(int nrows,int ncols){
    ??enableEvents(AWTEvent.TEXT_EVENT_MASK);
    ?}

    ?public void processTextEvent(TextEvent te){
    ??System.out.println("Processing a text event.");
    ?}
    }


    18.
    public class Outer {
    ?final String s = "i am outer class member variable";
    ?public void Method(){
    ??String s1 = "i am inner class variable";
    ??class InnerClass{
    ???String s2 = "i am inner class variable";
    ???public void innerMethod(){
    ????int xyz = 20;
    ????System.out.println(s);
    ????System.out.println("Integer value is " + xyz);
    ????System.out.println(s2);
    ???}
    ??}
    ?}
    ?public static void main(String[] args) {
    ??// TODO Auto-generated method stub

    ?}

    }



    19.
    public class Outerclass

    {

    private class InterClass

    {

    public InterClass()

    {

    System.out.println("InterClass Create");

    }

    }

    public Outerclass()

    {

    InterClass ic = new InterClass();

    System.out.println("OuterClass Create");

    }

    public static void main(String[] args)

    {

    Outerclass oc = new Outerclass();

    }

    }



    20.
    public class Parent1 {
    ? public void test(){ }
    ? public Parent1(){
    ???????? test();
    ??? }
    ? public static void main(String[] args){
    ???????? new Child1();
    ???? }
    }

    class Child1 extends Parent1{
    ??????? public int instanceValue = 20;
    ??????? public Child1(){
    ??????? ????? //super();
    ??????? ????? System.out.println("instance value isa: " + instanceValue);
    ??????? ? }
    ??? public void test(){
    ??????????? System.out.println("instance value is: " + instanceValue);
    ?????? }
    ? }

    posted on 2006-12-24 15:38 youngturk 閱讀(276) 評論(0)  編輯  收藏 所屬分類: 個人隨筆總結

    <2006年12月>
    262728293012
    3456789
    10111213141516
    17181920212223
    24252627282930
    31123456

    導航

    統計

    公告

    this year :
    1 jQuery
    2 freemarker
    3 框架結構
    4 口語英語

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊

    EJB學習

    Flex學習

    learn English

    oracle

    spring MVC web service

    SQL

    Struts

    生活保健

    解析文件

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 天天摸夜夜摸成人免费视频| 999国内精品永久免费观看| 国产免费人成视频在线观看| 亚洲色欲色欲www| 黄+色+性+人免费| 亚洲国产精品人久久电影| 亚洲精品在线免费观看| 无码乱人伦一区二区亚洲| 久热免费在线视频| 精品日韩亚洲AV无码| 久久精品免费一区二区| ass亚洲**毛茸茸pics| 最近最新MV在线观看免费高清| 在线综合亚洲中文精品| 免费黄色一级毛片| 猫咪免费观看人成网站在线| 亚洲精品成人区在线观看| 国产一级高青免费| 亚洲精品免费观看| 又黄又爽又成人免费视频| 亚洲欧美综合精品成人导航| 国产在线播放免费| 丝袜足液精子免费视频| 亚洲高清日韩精品第一区| 噼里啪啦电影在线观看免费高清| 亚洲AV第一成肉网| 青青草原亚洲视频| 日本视频一区在线观看免费| 亚洲欧美一区二区三区日产| 久久精品亚洲男人的天堂| 99热精品在线免费观看| 亚洲熟女乱色一区二区三区| 亚洲另类激情专区小说图片| 免费91麻豆精品国产自产在线观看| 亚洲国产精品久久久久秋霞影院 | xvideos亚洲永久网址| 中国一级毛片免费看视频| 亚洲成人高清在线观看| 免费国产成人午夜电影| 久久青草91免费观看| 亚洲经典千人经典日产|