fao java

Màu nền
Font chữ
Font size
Chiều cao dòng

Vai tro may ao,co che thuc thi trong java (ma nguon java, javabytecode (.class) thong qua may ao thong dich de chay tren nen tang nao do)

- tu khoa THIS de truy xuat den lop hien tai, tu khoa SUPER de tham khao lop cha

- overload cung ten khac tham so, override cung ten cung tham so

Phan Trac Nghiem:

1.vi sao java co the viet 1 lan chay o nhieu noi---vi java ho tro ca bien dich lan thong dich,co che thong do JVM thuc hien giup tao ra ma may cua tung nen tang khac nhau.

2. trong java ten 1public class va ten file phai trung nhau la ---dung

3.trinh nao se chuyen java sourcecode thanh byte code---trinh bien dich java

4.source code cua java co ten mo rong la gi--.class

5. int values []={1,2,…8};

   For (int i=0, i<x;i++) system.out.println (values[i]);

Voi gia tri la bao nhieu se in ra tat ca cac gia tri mang values----8

6. class Testsuper{

   Testsuper (int i){}

}

 Class testsub extends test super{}

Class test all {

 Public static void main (string[]args){

New testsub();}}------loi bien dich

7.nguoi ta xay dug lop A voi cac phuong thuc va lop B ke thua tu lop A. 1 phuong thuc cua B duoc goi la overriding 1 phuong thuc A neu---cung ten va cung bo tham so

1.bai hinh

//lop hinh

public class hinh {

            public double dientich(){return 0;}

            public double chuvi(){return 0;}

}

//lop hinhtron

public class hinhtron extends hinh{

            public double x0,y0,R;

            public hinhtron(double x, double y, double R0)

            {          x0=x;   y0=y;   R=R0;}

            public double dientich(){

                        double S=3.14*R*R;

                        return S;          }         

           public double chuvi()   {

                        double P=3.14*2*R;

                        return P;}}

//lop tamgiac

public class tamgiac extends hinh{

            public double xa,xb,xc,ya,yb,yc;

public tamgiac(double _xa,double _xb,double _xc,double _ya,double _yb,double _yc)

            {

                        xa=_xa;xb=_xb;xc=_xc;

                        ya=_ya;yb=_yb;yc=_yc;

            }

            public double D(double x1,double x2,double y1,double y2){

                        double D=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

                        return D;          }

            public double chuvi()  {

                        double AB=D(xa,xb,ya,yb);

                        double AC=D(xa,xc,ya,yc);

                        double BC=D(xb,xc,yb,yc);

                        double P=AB+AC+BC;

                        return P;          }

            public double dientich(){       

                        double AB=D(xa,xb,ya,yb);

                        double AC=D(xa,xc,ya,yc);

                        double BC=D(xb,xc,yb,yc);

                        double P= chuvi();

                        double S= Math.sqrt(P*(P-AB)*(P-AC)*(P-BC));

                        return S;}}

//lop main

public class main {

            /**

             * @param args

             */

            public static void main(String[] args)

            {

                        hinh[] arr=new hinh[10];

                        arr[0]=new tamgiac(1,1,1,2,3,3);

                        arr[1]=new tamgiac(1,4,6,2,3,3);

                        arr[2]=new hinhtron(1,1,3);

                        arr[3]=new hinhtron(0,0,5);

                        for (int i=0;i<10;i++)

                        if(arr[i] !=null)

                        {

                                    System.out.println("chu vi thu"+(i+1)+":"+arr[i].chuvi());

                                    System.out.println("dien tich thu"+(i+1)+":"+arr[i].dientich());

                        }}}

2.bai So Ao

public class SoAo{

            public int Phanthuc;

            public int Phanao;

            //hàm t?o

            public SoAo(){}

            public SoAo(int a, int b){

            this.Phanthuc=a;

            this.Phanao=b;            }

            public SoAo cong(SoAo So1,SoAo So2){

                        So1.Phanthuc=So1.Phanthuc + So2.Phanthuc;

                        So1.Phanao=So1.Phanao + So2.Phanao;

                        return So1;}

            public SoAo tru(SoAo So1,SoAo So2){

                        So1.Phanthuc=So1.Phanthuc - So2.Phanthuc;

                        So1.Phanao=So1.Phanao - So2.Phanao;

                        return So1;}

            public SoAo nhan(SoAo So1,SoAo So2){

                        So1.Phanthuc=(So1.Phanthuc*So2.Phanthuc - So1.Phanao * So2.Phanao) ;

                        So1.Phanao=So1.Phanao*So2.Phanthuc + So1.Phanthuc*So2.Phanao);

                        return So1;}

            public SoAo chia(SoAo So1,SoAo So2){

                        So1.Phanthuc=(So1.Phanthuc*So2.Phanthuc + So1.Phanao * So2.Phanao)/(So2.Phanthuc*So2.Phanthuc + So2.Phanao*So2.Phanao);

                        So1.Phanao= (So1.Phanthuc*So2.Phanao -So1.Phanao*So2.Phanthuc)/(So2.Phanthuc*So2.Phanthuc + So2.Phanao*So2.Phanao);

                        return So1;}

            public void HienThi()  {

            System.out.println(Phanthuc+"+"+ Phanao+"i");}

             public void Nhap(){

                         Scanner in =new Scanner(System.in);

                        System.out.println("Nhap so ao:");    

                        System.out.println("Phanthuc:");       

                        Phanthuc=in.nextInt();

                        System.out.println("Phanao:");          

                        Phanao=in.nextInt();   }}

public class main {

            /**

             * @param args

             */

            public static void main(String[] args)  {

                        /*SoAo s=new SoAo(2,3);

                        SoAo s1=new SoAo(4,5);

                        s.cong(s,s1);    s.HienThi();

                        s.tru(s,s1);        s.HienThi();

                        s.nhan(s,s1);    s.HienThi();

                        s.chia(s,s1);      s.HienThi();*/

                        /*SoAo s=new SoAo();

                        SoAo s1=new SoAo();

                        s.Nhap();         s1.Nhap();

                        s.cong(s,s1);    s.HienThi();

                        s.tru(s,s1);        s.HienThi();*/

                        }}

Bạn đang đọc truyện trên: Truyen2U.Pro