µ±Ç°Î»ÖãºÊ×Ò³ > ¸ß¼¶ÓïÑÔ³ÌÐòÉè¼Æ(Java) - ϰÌ⼯£¨º¬´ð°¸£©
18): public void showX() {
19): System.out.println(\20): } 21): };
22): public void showY() { 23): a.showX(); } 24): }
³ÌÐòµÚ5Ðеķ½·¨µ÷ÓÃÊä³öµÄ½á¹ûÈçºÎ£¿
153. ÔĶÁ³ÌÐò£¬»Ø´ðÎÊÌâ
1): public class A {
2): public static void main(String[] args) { 3): long first=1,second=1,third;
4): System.out.print(first + \ \ \5): for(int i = 3; i <= 6; i++) { 6): third = first + second;
7): System.out.print(third + \ \8): first = second; 9): second = third; 10): } 11): } 12): }
³ÌÐòÊä³öµÄ½á¹ûÊÇʲô£¿
154. д³öÏÂÁгÌÐòÍê³ÉµÄ¹¦ÄÜs
public class Sum{
public static void main( String args[ ]){
double sum = 0.0 ; for ( int i = 1 ; i <= 100 ; i + + ) sum += 1.0/(double) i ; System.out.println( \} }
155. д³öÏÂÁгÌÐòµÄ¹¦ÄÜ¡£
import java.io.*; public class Class1{ public static void main( String args[] ){ int i1=1234,i2=456,i3=-987;
int MaxValue;
MaxValue=max(i1,i2,i3);
System.out.println(\Èý¸öÊýµÄ×î´óÖµ£º\alue); }
public static int max(int x,int y,int z){
µÚ 13 Ò³ ¹² 33 Ò³
int temp1,max_value; temp1=x>y?x:y;
max_value=temp1>z?temp1:z; return max_value;
} }
156. д³öÏÂÁгÌÐòµÄ¹¦ÄÜ
import java.io.*;
public class Class1 { public static void main( String args[ ] ){
SubClass a = new SubClass( 10,3 );
System.out.println( a.exp( )); } }
class SuperClass { float x; int n;
SuperClass(float xx,int nn ) {
x = xx ; n = nn; } }
class SubClass extends SuperClass{
SubClass(float xx , int nn) {
super( xx , nn ); }
float exp( ) { float s = 1;
for ( int i = 1; i <= n; i++ )
s = s*x; return s; } }
157. ÔĶÁ³ÌÐò£¬»Ø´ðÎÊÌâ
1): public class A {
2): public static void main(String args[]) { 3): MyInterface obj2=new B(\4): obj2.show(); 5): }
µÚ 14 Ò³ ¹² 33 Ò³
6): } 7):
8): interface MyInterface { 9): double G=88; 10): void show(); 11): } 12):
13): class B implements MyInterface { 14):
15): String str;
16): public B(String s) { 17): str=s; 18): }
19): public void show() {
20): System.out.println(str+\21): } 22): }
³ÌÐòµÚ8~11Ðж¨ÒåµÄMyInterfaceÊÇÀ໹Êǽӿڣ¿³ÌÐòµÚ4ÐÐÊä³öµÄ½á¹ûÊÇʲô£¿
158. ÔĶÁÏÂÃæµÄ³ÌÐò£¨»ò³ÌÐòƬ¶Î£©£¬»Ø´ðÎÊÌâ ¡£
ÏÖÓÐÀà˵Ã÷ÈçÏ£º
class A{
int x=10; int GetA(){
return x; } }
class B extends A{
int x=100; int GetB(){
return x; } }
ÈôbÊÇÀàBµÄ¶ÔÏó£¬Ôòb.GetA()µÄ·µ»ØÖµÊÇʲô£¿
159. ÔĶÁÒÔϳÌÐò¶Î£¬»Ø´ðÎÊÌâ¡£
class Parent{ void printMe(){ System.out.println(¡°parent¡±);
} }
class Child extends Parent{ void printMe(){ System.out.println(¡°child¡±);
µÚ 15 Ò³ ¹² 33 Ò³
}
public class Test_this{ public static void main(String args[ ]){ Child myC=new Child(); myC.printAll();
} }
Êä³ö½á¹ûÊÇʲô£¿
}
void printAll(){ super.printMe(); this.printMe(); printMe(); }
160. ÔĶÁ³ÌÐò£¬»Ø´ðÎÊÌâ¡£
1): public class A {
2): public static void main(String args[]) { 3): try{
4): int x[]={1,2,3};
5): int k=Integer.parseInt(args[0]); 6): System.out.println(x[k]);
7): System.out.println(\½áÊø£¡\8): }
9): catch(ArrayIndexOutOfBoundsException e){ 10): System.out.println(\Ö´ÐÐcatch\11): }
12): finally{
13): System.out.println(\Ö´ÐÐfinally\14): }
15): System.out.println(\³ÌÐò½áÊø£¡\16): } 17): }
ÈôÔÚÃüÁîÐбàÒë¸Ã³ÌÐòºó£¬¼üÈëÏÂÃæµÄÄÚÈÝÔËÐиóÌÐò£º java A 3
Ôò³ÌÐòÊä³öµÄ½á¹ûÈçºÎ£¿
161. ÔĶÁÏÂÃæµÄ³ÌÐò£¬»Ø´ðÎÊÌâ¡£
class student{ String name;
int age;
µÚ 16 Ò³ ¹² 33 Ò³
¹²·ÖÏí92ƪÏà¹ØÎĵµ