Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Lektsii_1-7_Test_1_Var_2_4.doc
Скачиваний:
0
Добавлен:
01.04.2025
Размер:
83.97 Кб
Скачать

6. Какие модификаторы можно использовать в строке 5, чтобы код компилировался без ошибок?

  1. public class Ancestor {

  2. static double calc(double x){return x*x;}

  3. }

  4. public class Successor extends Ancestor {

  5. … … … calc(double x){return ++x*++x;}

  6. }

  1. static private double calc(double x)

  2. static void calc(double x)

  3. public double calc(double x)

  4. static public double calc(double x)

  5. double calc(double x)

  6. final public double calc(double x)

7. Какая из строк кода компилируется с ошибкой?

  1. char c1=50,c2=10;

  2. short s; int i;

  1. s=(short)(c1-c2);

  2. System.out.println("subtraction="+s);

  3. System.out.println("subtraction="+(c1-c2));

  4. i=c1-c2;

  5. System.out.println("subtraction="+i);

  6. c1=(char)c1-c2;

  7. System.out.println("subtraction="+(char)c1);

8. Какой из методов, членов класса Equivalent, будет вызван в строке 5?

  1. class Equivalent{

  2. void inform(…){…};

  3. public static void main(String[] args) {

  4. Equivalent eq=new Equivalent();

  5. eq.inform('c');}}

  1. void inform(short s){System.out.println("Short inform "+s);}

  2. void inform(String str){System.out.println("String inform "+str);}

  3. void inform(float x){System.out.println("Float inform "+x);}

  4. void inform(long i){System.out.println("Long inform "+i);}

9. Что будет напечатано, если файл не найден, хотя url адрес определен правильно?

  1. public void init() {

  2. AppletContext ac=getAppletContext();

  3. URL url1,url;

  4. url=getCodeBase();

  5. try{

  6. url1=new URL(url+"HTML.htm");

  7. ac.showDocument(url1);

  8. }catch(MalformedURLException e){System.out.println("URL exception");}

  9. catch(IOException e){System.out.println("IO exception");}

  10. catch(Exception e){System.out.println("General exception");}

  11. finally{System.out.println("Finally part");};

  12. System.out.println("Carrying on");

  13. }

  1. Ничего не будет напечатано

  2. General exception

  3. URL exception

  4. IO exception

  5. Finally part

  6. Carrying on

10. Метод readFile(), может выбрасывать исключения ioException и FileNotFoundException. Как правильно вызывать этот метод?

A).

    1. public void call () {

    2. try{ bytes = readFile();

    3. }catch(FileNotFoundException e){…}

    4. catch (EOFException e){…}; }

B).

  1. public static void main(String[] args) throws Exception{

  2. byte bytes[]= new byte[100];

  3. bytes = readFile();

  4. for(int i=0;i<100;i++){System.out.println(bytes[i]);};

}

C).

  1. public void call () {

  2. try{ bytes = readFile();

  3. } catch(IOException e){…}

  4. catch(FileNotFoundException e){…} }

D).

    1. public void call () {

    2. try{ bytes = readFile() throw FileNotFoundException ;

    3. } catch(IOException e){…} }

E).

  1. public static void main(String[] args)throws FileNotFoundException{

  2. byte bytes[]= new byte[100];

  3. bytes = readFile();

  4. for(int i=0;i<100;i++){System.out.println(bytes[i]);};

  5. }

11. Какие из методов можно поместить в строке 3 класса Polymorph?

  1. public class Polymorph {

  2. public float method(float a) throws RuntimeException{ return 7.0F;}

  3. ???

  4. }

  1. public float method(float a){return 7.0F;}

  2. public int method(float a) throws ArithmeticException{return 7;}

  3. private float method(float a) throws NoSuchMethodException{return 7.0F;}

  4. public float method(float x,float y) throws NoSuchMethodException{ return 7F;}

  5. public String method(float x) throws MalformedURLException {return "OK";}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]