Программирование на Java - ответы
Количество вопросов - 374
import java.awt.Point; public class Obscuring { static Point Test = new Point(3,2); public static void main (String s[]) { System.out.println(Test.x); } } class Test { static int x = -5; }
class abc.Point { abc.Point(int a, int b) { x = a; y = b; } int x, y; ... }Укажите результат выполнения следующего фрагмента кода:
abc.Point p = new abc.Point(5,3), p1; p1 = p; p = null; System.out.println(p.x);
public class SomeClass { public static void main(String[] args) { ____ for (int i = 0; i < b.length; i++) { System.out.print(b[i]); } } }
public abstract class SomeClass implements Runnable{ private Object lock = new Object(); public void lock() { synchronized (lock) { try { System.out.print("1"); lock.wait(); } catch (InterruptedException e) {} } } public void unlock() { synchronized (lock) { lock.notify(); System.out.print("2"); } } public static void main(String s[]) { new Thread(new SomeClass() { public void run() { lock(); } }).start(); new Thread(new SomeClass() { public void run() { unlock(); } }).start(); } }
Exception | +--LengthException | +--TooLongException | +--TooShortException 1 class BaseMeasurer{ 2 int measureLength(Dimension d) throws TooShortException{..} 3 } 4 class DerivedMeasurer extends BaseMeasurer{ 5 ___ { 6 } 7 }Какое из перечисленных ниже выражений можно использовать в строке 5 вместо знаков подчеркивания, чтобы код успешно откомпилировался?
int x = 0; /* text // text */int y=1; // text */ // text */
int a = 5; int b = 6; ++a = b++; System.out.println(a);
class abcPoint { abcPoint(int a, int b) { x = a; y = b; }int x, y;...}Укажите результат выполнения следующего фрагмента кода:
abcPoint p = new abcPoint(5,3), p1 = p;p.x = 4;System.out.println(p1.x);
int a = 1; short b = 1; long c = 1; ? d = a + b;
class abc.SomeClass {} class abc.SomeClass2 extends abc.SomeClass {}Что будет выведено на экран в следующем фрагменте кода:
abc.SomeClass x1 = new abc.SomeClass(); abc.SomeClass2 x2 = new abc.SomeClass2(); System.out.println((x1 instanceof abc.SomeClass) + " " + (x2 instanceof abc.SomeClass2));
class Box { private int weight=0; public int getWeight() { return weight; } void setWeight(int weight) { this.weight=weight; } }
public class Flat{ private int floor_number; private int roomNumber; public int rooms() { return roomNumber; } public int getFloorNumber() { return floor_number; } }
long a = 3; a = 5 + a; System.out.print("a = " + a);
Wolf w = new Wolf(); Animal a = (Animal)w; Rabbit r = (Rabbit)a;
public class SomeClass { public static void main(String[] args) { SomeClass c = new SomeClass(); c.f1(1, 1); } public void f1(byte b, char c) { System.out.println("1"); } public void f1(byte b, byte c) { System.out.println("2"); } public void f1(char b, char c) { System.out.println("3"); } public void f1(char b, byte c) { System.out.println("4"); } }
public class SomeClass { public static void main(String[] args) { SomeClass c = new SomeClass2(); }}class SomeClass2 extends SomeClass {}
public class SomeClass { public void perform() { this.perform(1); System.out.print("1"); } public void perform(int val) { System.out.print(val); } public static void main(String[] args) { SomeClass c = new SomeClass2(); c.perform(4); } } class SomeClass2 extends SomeClass { public void perform() { super.perform(); System.out.print("3"); } public void perform(int val) { super.perform(); System.out.print(val); } }
class Parent { static int x = 2; static public void print() { System.out.println(x); } } class Child extends Parent { static int x = 3; public static void main(String[] args) { Parent c = new Child(); c.print(); } }
int b[] = new int[5]; for (int i = 0; i < b.length(); i++) { b[i] = Math.sqrt(i); }
public class SomeClass { public static void main(String[] args) { ____ for (int i = 0; i < b.length; i++) { System.out.print(b[i]); } } }
public class Vehicle { public static void main(String[] args) { Vehicle[] v = new Car[] { new Car()}; ... } public void setVehicles(Vehicle c[]) { c[0] = new Vehicle(); } public void setVehicles2(Vehicle c[]) { if (c[0] instanceof Vehicle) { c[0] = new Car(); } } public void setVehicles3(Vehicle c[]) { if (c[0] instanceof Car) { c[0] = new Vehicle(); } } } class Car extends Vehicle{}
public class SomeClass { public static void main(String[] args) { int a[] = {1, 2, 3}; int b[] = (int[]) a.clone(); a[0] = 0; System.out.print(b[0]); System.out.print(b[1]); System.out.print(b[2]); } }
public class SomeClass { static int x; public static void main(String[] args) { SomeClass s = new SomeClass(); s.test(5); System.out.println(x); } private void test(int x) { this.x = x + 5; System.out.print(x); } }
1 public class SomeClass {2 public static void main(String[] args) {3 String[] arr = {"H", "e", "l", "l", "o", " ", "W", "o", "r", "l", "d", "!"};4 String result = "";5 int i = 0;6 ...7 System.out.print(arr[i]);8 }9 }
public class SomeClass { public static void main(String[] args) { SomeClass t = new SomeClass(); ____ } private int check(String x, int n) { if (n == 0) return n; else if (n == 1) { if (x != null) return 5; } else if (n == 2 && x != null) { if (x.equals("YES")) return 3; else if (x.equals("NO")) return 4; } return -1; } }Если вместо знаков подчеркивания поместить код вызова метода check, то какое из предложений будет верным?
public class SomeClass { public static void main(String[] args) { SomeClass t = new SomeClass(); t.say(3); } private void say(int digit) { switch (digit) { case 1: System.out.print("ONE"); break; case 2: System.out.print("TWO"); case 3: System.out.print("THREE"); default: System.out.print("Unknown"); } } }
public class SomeClass { public static void main(String[] args) { int i = 0; do { if (i > 5) i--; if (i < 4) i++; if (i == 5) i++; i++; System.out.print(i); } while (i <= 6); } }
public class Test { public static void main(String[] args) { Test t = new Test(); t.test(); } void test() { Test:{ test: for (int i = 0; true; i++) { if (i % 2 == 0) continue test; if (i > 10) break Test; System.out.print(i); } } } }
java.lang.Object | +--java.lang.Throwable | +--java.lang.Exception | +--java.lang.RuntimeException | +--java.lang.IndexOutOfBoundsException | +--java.lang.StringIndexOutOfBoundsException | +--java.lang.ArrayIndexOutOfBoundsExceptionВ методе testSomеValue могут быть возбуждены исключения StringIndexOutOfBoundsException и ArrayIndexOutOfBoundsException, при этом они не обрабатываются в блокеtry – catch. Какие из перечисленных ниже утверждений будут верными?
Exception | +--LengthException | +--TooLongException | +--TooShortException 1 class BaseMeasurer{ 2 int measureLength(Dimension d) throws TooLongException{..} 3 } 4 class DerivedMeasurer extends BaseMeasurer{ 5 ___ { 6 } 7 }Какое из перечисленных ниже выражений можно использовать в строке 5 вместо знаков подчеркивания, чтобы код успешно откомпилировался?
public abstract class SomeClass implements Runnable { public final static Object one = new Object(), two = new Object(); public static void main(String s[]) { Thread t1 = new Thread() { public void run() { synchronized (one) { synchronized (two) { System.out.print("1"); } } } }; Thread t2 = new Thread() { public void run() { synchronized (two) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } synchronized (one) { System.out.print("2"); } } } }; t1.start(); t2.start(); } }
public abstract class SomeClass implements Runnable{ public Object lock = new Object(); public void lock() { synchronized (lock) { try { lock.wait(); System.out.print("1"); } catch (InterruptedException e) {} } } public void notifyThread() { synchronized (lock) { lock.notify(); } } public void unlock() { synchronized (lock) { lock.notify(); System.out.print("2"); } } public static void main(String s[]) { final SomeClass c = new SomeClass() { public void run() { lock(); } }; final SomeClass c1 = new SomeClass() { public void run() { unlock(); c.notifyThread(); } }; new Thread(c).start(); new Thread(c1).start(); } }
public abstract class SomeClass implements Runnable{ private Object lock = new Object(); public void lock() { synchronized (lock) { try { lock.wait(); System.out.print("1"); } catch (InterruptedException e) {} } } public void unlock() { synchronized (lock) { lock.notify(); System.out.print("2"); } } public static void main(String s[]) { new Thread(new SomeClass() { public void run() { lock(); } }).start(); new Thread(new SomeClass() { public void run() { unlock(); } }).start(); } }
1 - Коаксиальный кабель 2 - Оптоволокно 3 - Телефонный кабель 4 - Витая пара
public class SomeClass { public static void main(String s[]) { Calendar cal = new GregorianCalendar(); cal.set(Calendar.YEAR, 2011); cal.set(Calendar.MONTH, Calendar.APRIL); cal.set(Calendar.DAY_OF_MONTH, 30); cal.add(Calendar.DAY_OF_MONTH, 1); cal.roll(Calendar.MONTH, 11); SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMMM dd"); System.out.println(sdf.format(cal.getTime())); } }
public class SomeClass { public static void main(String[] args) { SomeClass t = new SomeClass(); t.say(2); } private void say(int digit) { switch (digit) { case 1: System.out.print("ONE"); break; case 2: System.out.print("TWO"); case 3: System.out.print("THREE"); break; default: System.out.print("Unknown"); } } }
int b[] = new int[5]; for (int i = 0; i <= b.length(); i++) { b[i] = Math.sqrt(i); }
public class SomeClass { public static void main(String[] args) { SomeClass c = new SomeChild2(); ((SomeClass)c).print(); ((SomeChild1)c).print(); ((SomeChild2)c).print(); } public void print() { System.out.println("SomeClass"); } } class SomeChild1 extends SomeClass { public void print() { System.out.println("SomeChild1"); } } class SomeChild2 extends SomeClass { public void print() { System.out.println("SomeChild2"); } }
class abc.Point { abc.Point(int a, int b) { x = a; y = b; } int x, y; ... }Укажите результат выполнения следующего фрагмента кода:
abc.Point p = new abc.Point(5,3), p1; System.out.println(p1 == p);
long a = 111111111111L; double f = a; long b = 11111L; double d = b; System.out.println( a == (long) f); System.out.println( b == (long) d);
public class SomeClass { public static void main(String[] args) { SomeClass c = new SomeChild1(); ((SomeClass)c).print(); ((SomeChild1)c).print(); ((SomeChild2)c).print(); } public void print() { System.out.println("SomeClass"); } } class SomeChild1 extends SomeClass { public void print() { System.out.println("SomeChild1"); } } class SomeChild2 extends SomeClass { public void print() { System.out.println("SomeChild2"); } }
class Parent { int x = 2; public void print() { System.out.println(x); } } class Child extends Parent { int x = 3; public static void main(String[] args) { new Child().print(); } public void print(String val){ System.out.println(val); } }
public class Vehicle { public static void main(String[] args) { Vehicle[] v = new Car[] { new Car()}; ... } public void setVehicles(Vehicle c[]) { c[0] = new Vehicle(); } public void setVehicles2(Vehicle c[]) { if (c[0] instanceof Car) { c[0] = new Vehicle(); } } public void setVehicles3(Vehicle c[]) { if (c[0] instanceof Vehicle) { c[0] = new Car(); } } } class Car extends Vehicle{}
public class SomeClass { static int x = 5; public static void main(String[] args) { int x; int y = 5; if (y > 3) x = 1; System.out.println(x); } }
1 public class SomeClass { 2 public static void main(String[] args) { 3 String[] arr = {"H", "e", "l", "l", "o", " ", "W", "o", "r", "l", "d", "!"}; 4 String result = ""; 5 int i = 0; 6 ... 7 System.out.print(arr[i++]); 8 } 9 }
public class SomeClass { public static void main(String[] args) { SomeClass t = new SomeClass(); t.say(1); } private void say(int digit) { switch (digit) { case 1: System.out.print("1"); break; case 2: System.out.print("2"); case 3: System.out.print("3"); default: System.out.print("Unknown"); } } }
public class Test { public static void main(String[] args) { Test t = new Test(); t.test(); } void test() { Test:{ test: for (int i = 0; true; i++) { if (i % 2 == 0) continue test; if (i > 10) break test; System.out.print(i); } } } }
public abstract class SomeClass implements Runnable { public final static Object one = new Object(), two = new Object(); public static void main(String s[]) { Thread t1 = new Thread() { public void run() { synchronized (one) { synchronized (two) { System.out.print("1"); } } } }; Thread t2 = new Thread() { public void run() { synchronized (two) { synchronized (one) { System.out.print("2"); } } } }; t1.start(); t2.start(); } }
public abstract class SomeClass implements Runnable{ private Object lock = new Object(); public void lock() { synchronized (lock) { try { lock.wait(); System.out.print("1"); } catch (InterruptedException e) {} } } public void notifyThread() { synchronized (lock) { lock.notify(); } } public void unlock() { synchronized (lock) { lock.notify(); System.out.print("2"); } } public static void main(String s[]) { Thread t = new Thread(new SomeClass() { public void run() { lock(); try { Thread.sleep(1000); } catch (InterruptedException e) {} notifyThread(); } }); t.start(); Thread t1 = new Thread(new SomeClass() { public void run() { unlock(); } }); t1.start(); } }
public class SomeClass { public void perform() { System.out.print("1"); } public static void main(String[] args) { SomeClass c = new SomeClass2(); c.perform(); } } class SomeClass2 extends SomeClass { public void perform() { ____ System.out.print("2"); } }
public class Vehicle { public static void main(String[] args) { Vehicle[] v = new Car[5]; ... } public void setVehicles(Vehicle c[]) { c[0] = new Vehicle(); } public void setVehicles2(Vehicle c[]) { if (c[0] instanceof Vehicle) { c[0] = new Vehicle(); } } public void setVehicles3(Car c[]) { if (c[0] instanceof Car) { c[0] = new Car(); } } } class Car extends Vehicle{}
public class SomeClass { public static void main(String[] args) { int a[] = {1, 2, 3}; int b[] = (int[]) a.clone(); a[0] = 0; System.out.print(b[0]); }}
class Parent { public void print() { System.out.println(x); } } class Child extends Parent { int x = 3; public static void main(String[] args) { Parent c = new Child(); c.print(); } }
1 public class SomeClass { 2 public static void main(String[] args) { 3 String[] arr = {"H", "e", "l", "l", "o", " ", "W", "o", "r", "l", "d", "!"}; 4 String result = ""; 5 int i = 0; 6 ... 7 System.out.print(arr[++i]); 8 } 9 }
public class SomeClass { public static void main(String[] args) { int i = 0; while (i < 6) { if (i > 5) i--; if (i < 4) i++; if (i == 5) i++; i++; System.out.print(i); } } }
public class Test { public static void main(String[] args) { Test t = new Test(); t.test(); } void test() { Test:{ test: for (int i = 0; true; i++) { if (i % 2 == 0) continue Test; if (i > 10) break Test; System.out.print(i); } } } }
java.lang.Object | +--java.lang.Throwable | +--java.lang.Exception | +--java.lang.RuntimeException | +--java.lang.IndexOutOfBoundsException | +--java.lang.StringIndexOutOfBoundsException | +--java.lang.ArrayIndexOutOfBoundsExceptionВ методе testSomеValue могут быть возбуждены исключения StringIndexOutOfBoundsException и ArrayIndexOutOfBoundsException, при этом они не обрабатываются в блокеtry – catch. Какое из перечисленных ниже утверждений будет верным?
public class SomeClass { public static void main(String[] args) { ____ for (int i = 0; i < b.length; i++) { System.out.print(b[i]); } } }
public class SomeClass { static int x; public static void main(String[] args) { SomeClass s = new SomeClass(); s.test(5); System.out.println(x); } private void test(int x) { x = this.x + 5; System.out.print(x); } }
Exception | +--LengthException | +--TooLongException | +--TooShortException 1 class BaseMeasurer{ 2 int measureLength(Dimension d) throws LengthException{..} 3 } 4 class DerivedMeasurer extends BaseMeasurer{ 5 ___ { 6 } 7 }Какие из перечисленных ниже выражений можно использовать в строке 5 вместо знаков подчеркивания, чтобы код успешно откомпилировался?
class Parent { int x = 2; public void print() { System.out.println(x); } } class Child extends Parent { int x = 3; public static void main(String[] args) { new Child().print(); } }
public class SomeClass { public static void main(String[] args) { int a[][] = {{1, 2}, {3}}; int b[][] = (int[][]) a.clone(); a[0] = new int[]{0}; System.out.println(b[0][0]); }}
public abstract class SomeClass implements Runnable { public final static Object one = new Object(), two = new Object(); public static void main(String s[]) { Thread t1 = new Thread() { public void run() { synchronized (one) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } synchronized (two) { System.out.print("1"); } } } }; Thread t2 = new Thread() { public void run() { synchronized (two) { synchronized (one) { System.out.print("2"); } } } }; t1.start(); t2.start(); } }
public abstract class SomeClass implements Runnable{ private Object lock = new Object(); public void lock() { synchronized (lock) { try { lock.wait(); System.out.print("1"); } catch (InterruptedException e) {} } } public void notifyThread() { synchronized (lock) { lock.notify(); } } public void unlock() { synchronized (lock) { lock.notify(); System.out.print("2"); } } public static void main(String s[]) { SomeClass c = new SomeClass() { public void run() { lock(); } }; SomeClass c1 = new SomeClass() { public void run() { unlock(); } }; new Thread(c).start(); new Thread(c1).start(); c.notifyThread(); } }
public abstract class SomeClass implements Runnable{ public static Object lock = new Object(); public void lock() { synchronized (lock) { try { lock.wait(); System.out.print("1"); } catch (InterruptedException e) {} } } public void notifyThread() { synchronized (lock) { lock.notify(); } } public void unlock() { synchronized (lock) { lock.notify(); System.out.print("2"); } } public static void main(String s[]) { final SomeClass c = new SomeClass() { public void run() { lock(); notifyThread(); } }; final SomeClass c1 = new SomeClass() { public void run() { unlock(); } }; new Thread(c).start(); new Thread(c1).start(); } }
int x = 0; /* комментарий // комментарий /* int y = 1; // комментарий */ // комментарий */
System.out.println(1/0); System.out.println(1./0); System.out.println(1/0.); System.out.println(1./0.); System.out.println('\n'+'\r');
int a = 5, b = 6; a = b++; System.out.println(++a == b++);
int a = 1;short b = 1;long c = 1;c = (d = a + c) ? a : b;
class abc.Point { abc.Point(int a, int b) { x = a; y = b; } int x, y; ... }Укажите результат выполнения следующего фрагмента кода:
abc.Point p = new abc.Point(5,3), p1; p1 = p; p = null; System.out.println(p1.x);
class SomeClass {} class SomeClass2 extends SomeClass {}Что будет выведено на экран в следующем фрагменте кода:
SomeClass x1 = new SomeClass(); SomeClass2 x2 = new SomeClass2(); System.out.println((x1 instanceof SomeClass2) + " " + (x2 instanceof SomeClass2));
public class flat{ private int floorNumber; private int roomNumber; public int rooms() { return roomNumber; } public int GetFloorNumber() { return floorNumber; } }
public class SomeClass { public static void main(String[] args) { SomeClass s = new SomeClass("5", "6"); SomeClass s1 = new SomeClass("10", "12"); s1.doSomething(s); System.out.print(s1.x + s1.y + s.x + s.y); } private void doSomething(SomeClass s) { s.x = "5"; this.y = "6"; } public SomeClass(String x, String y) { this.x = x; this.y = y; } String x, y; }
public class SomeClass { public static void main(String[] args) { SomeClass c = new SomeClass(); c.f1(1, 1); } public void f1(int b, long c) { System.out.println("1"); } public void f1(long b, int c) { System.out.println("2"); } public void f1(int b, int c) { System.out.println("3"); } public void f1(long b, long c) { System.out.println("4"); } }
public class SomeClass { public static void main(String[] args) { SomeClass c = new SomeClass2(); SomeClass2 c2 = new SomeClass2(); c2.print(); c.print(); } } class SomeClass2 extends SomeClass { public void print() { System.out.println("message"); } }
public class SomeClass { int b = this.a; int a = 5; { System.out.print(a); System.out.print(b); } public static void main(String[] args) { new SomeClass(); } }
public class SomeClass { public static void main(String[] args) { int i = 0; do { if (i > 5) i--; if (i < 4) i++; if (i == 5) i+=2; i++; System.out.print(i); } while (i <= 5); } }
public class SomeClass { public static void main(String[] args) { SomeClass t = new SomeClass(); ____ } private int check(String x, int n) { if (n == 0) return n; else if (n == 1) { if (x != null) return 5; } else if (n == 2 && x != null) { if (x.equals("YES")) return 3; else if (x.equals("NO")) return 4; } return -1; } }Если вместо знаков подчеркивания поместить код вызова метода check, то какое из предложений будет верным?
int a = 5, b = 6; a = b++; System.out.println(a);
class abc.Point { abc.Point(int a, int b) { x = a; y = b; } int x, y; ... }Укажите результат выполнения следующего фрагмента кода:
abc.Point p = new abc.Point(5,3), p1 = p; System.out.println(p1 == p);
int a = 1; short b = 1; long c = 1; ? d = a + b + c;
long a = 3; a = 5 + 'A' + a; System.out.print("a = " + a);
public class SomeClass { public static void main(String[] args) { SomeClass t = new SomeClass(); ____ } private int check(String x, int n) { if (n == 0) return n; else if (n == 1) { if (x != null) return 5; } else if (n == 2 && x != null) { if (x.equals("YES")) return 3; else if (x.equals("NO")) return 4; } return -1; } }Если вместо знаков подчеркивания поместить код вызова метода check, то какое из предложений будет верным?
public class SomeClass { public static void main(String args[]) { SomeClass s = new SomeClass(); System.out.println(s.x + ", " + s.y); } int getX() { return x; } int y = getX(); int x = 3; }
int x = 0; /* комментарий // комментарий */ String s = "text/*комментарий*/";
class abc.Point { abc.Point(int a, int b) { x = a; y = b; } int x, y; ... }Каков будет результат следующего примера?
abc.Point p1 = new abc.Point(3, 4); abc.Point p2 = p1; p1.x = 5; p1 = new abc.Point(4, 4); System.out.print(p2.x - p1.x);
MyClass MyClass.name MyClass.name.toString() MyClass.name.toString().hashCode()
long a = 3; a = 5 + 'A' + a;
public class SomeClass { public static void main(String[] args) { SomeClass c = new SomeClass(); c.f1(1, 1); } public void f1(Integer i1, Integer i2) { System.out.println("1"); } public void f1(Integer i1, int i2) { System.out.println("2"); } public void f1(int b, Integer c) { System.out.println("3"); } public void f1(long b, long c) { System.out.println("4"); } }
class abc.SomeClass {} class abc.SomeClass2 extends abc.SomeClass {}Что будет выведено на экран в следующем фрагменте кода:
abc.SomeClass x1 = new abc.SomeClass(); abc.SomeClass2 x2 = new abc.SomeClass2(); System.out.println((x1 instanceof abc.SomeClass) + " " + (x2 instanceof abc.SomeClass));
public class flat{ private int floor_number; private int r; // количество комнат public int getR() { return r; } public int getFloorNumber() { return floor_number; } }
java.lang.Object | +--java.lang.Throwable | +--java.lang.Exception | +--java.lang.RuntimeException | +--java.lang.IndexOutOfBoundsException | +--java.lang.StringIndexOutOfBoundsException | +--java.lang.ArrayIndexOutOfBoundsExceptionВ методе testSomеValue могут быть возбуждены исключения StringIndexOutOfBoundsException и ArrayIndexOutOfBoundsException, при этом они не обрабатываются в блокеtry – catch. Какое из перечисленных ниже утверждений будет верным?
long a = 111111111111L; float f = a; long b = 11111L; float d = b; System.out.println( a == (long) f); System.out.println( b == (long) d);
public class SomeClass { public static void main(String args[]) { SomeClass2 s = new SomeClass2(); } public SomeClass() { System.out.print("1"); } { System.out.print("2"); } } class SomeClass2 extends SomeClass { public SomeClass2() { System.out.print("3"); } { System.out.print("4"); } }
class Box { private int weight=0; public int getWeight() { return weight; } void setWeight(int weight) { weight=weight; } }