单选题public class TestSeven extends Thread { private static int x; public synchronized void doThings() { int current = x; current++; x = current; } public void run() { doThings(); } } Which is true?()A Compilation fails.B An exception is thrown at runtime.C Synchronizing the run() method would make the class thread-safe.D The data in variable “x” are protected from concurrent access problems.E Declaring the doThings() method as static would make the class thread-safe.F Wrapping the statements within doThings() in a synchronized(new Object()) {} block would make the class thread-safe.
单选题
public class TestSeven extends Thread { private static int x; public synchronized void doThings() { int current = x; current++; x = current; } public void run() { doThings(); } } Which is true?()
A
Compilation fails.
B
An exception is thrown at runtime.
C
Synchronizing the run() method would make the class thread-safe.
D
The data in variable “x” are protected from concurrent access problems.
E
Declaring the doThings() method as static would make the class thread-safe.
F
Wrapping the statements within doThings() in a synchronized(new Object()) {} block would make the class thread-safe.
参考解析
解析:
暂无解析
相关考题:
能将程序补充完整的选项是( )。class Person{ private int a; public int change(int m){ return m; }}public class Teacher extends Person{ public int b; public static void main(String arg[]) { Person p = new Person(); Teacher t = new Teacher(); int i; ______ }} B.A.i=mB.i=bC. i=p.aD.i=p. change(50)
能将程序补充完整的选项是______。 class Person{ private int a; phblic int change(int m){return m;} } public class Teacher extends Person{ public int b; public static void main(String arg[ ]){ Person p=new Person( ); Teacher t=new Teacher( ); int i; ______; } }A.i=mB.i=bC.i=p.aD.i=p.change(50)
给出下列代码,如何使成员变量m被方法fun( )直接访问?Class Test{private int m;public static void fun( ){} }A.将private int m改为protected int mB.将private int m改为public int mC.将private int m改为static int mD.将private int m改为int m
给出下列代码,如何使成员变量m被方法fun( )直接访问? class Test{ private int m; public static void fun( ){ … } }A.将private int m改为protected int mB.将private int m改为public int mC.将private int m改为static iD.将private int m改为int m
在下列程序的划线处应填入的语句是class Person { private int a;}public class Man extends Person{ public int b; public static void main (String arg []){ Person p=new Person(); Man t=new Man(); int i: }}A.i=w;B.i=bC.i=p.a;D.i=t.b;
在下面程序的下画线处应填入的选项是 public class Test______{ public static void main(String args[]) { Test t=new Test(); Thread tt=new Thread(t); tt.start(); } public void run() { for(int i=0;i<5;i++) System.out.println("i="+i); } }A.implements RunnableB.extends ThreadC.implements ThreadD.extends Runnable
interface A{int x = 0;}class B{int x =1;}class C extends B implements A {public void pX(){System.out.println(x);}public static void main(String[] args) {new C().pX();}}
下列程序创建了一个线程并运行,横线处应填入的正确代码是( )。 public class Try extends Thread{ public static void main(String args[]){ Thread t=new Try; ; } public void runf System.out.println(”Try!"); } }A.t.startB.t.classC.t.threadD.t.static
请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。[题目要求]生成下面左边图形界面,单击图中的New按钮,弹出如右图所示的对话框。源程序:import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Java_3 {public static void main(String[] args) {MulticastFrame. frame=new MulticastFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.show();}}class MulticastFrame. extends JFrame. {public MulticastFrame() {setTitle("MulticastTest");setSize(WIDTH,HEIGHT);MulticastPanel panel=new MulticastPanel();Container contentPane=getContentPane();contentPane.add( (1) );}public static final int WIDTH=300;public static final int HEIGHT=200;}class MulticastPanel extends JPanel }public MulticastPanel() {JButton newButton=new JButton("New");add(newButton);ActionListener newListener=new ActionListener() {public void actionPerformed(ActionEvent event) {makeNewFrame();}};newButton.addActionListener(newListener);closeAllButton=new JButton("Close all");add(closeAllButton);}private void makeNewFrame() {final BlankFrame. frame=new BlankFrame();frame.show();ActionListener closeAllListener=new ActionListener() {public void actionPerformed(ActionEvent event) {frame. (2) (); //使窗口隐藏或消除}};closeAllButton.addActionListener( (3) );}private JButton closeAllButton;}Class BlankFrame. extends JFrame. {public BlankFrame() {(4) ++;setTitle("Frame"+counter);setSize(WIDTH,HEIGHT);setLocation(SPACING*counter,SPACING*counter);}public static final int WIDTH=200;public static final int HEIGHT=150;public static final int SPACING=30;private static int counter=0;}
( 30 )在程序的下划线处应填入的选项是public class Test _________{public static void main(String args[]){Test t = new Test();Thread tt = new Thread(t);tt.start();}public void run(){for(int i=0;i5;i++){system.out.println( " i= " +i);}}}A ) implements RunnableB ) extends ThreadC ) implements ThreadD ) extends Runnable
class A { protected int method1(int a, int b) { return 0; } } Which two are valid in a class that extends class A?() A、 public int method1(int a, int b) { return 0; }B、 private int method1(int a, int b) { return 0; }C、 private int method1(int a, long b) { return 0; }D、 public short method1(int a, int b) { return 0: }E、 static protected int method1(int a, int b) { return 0; }
Which statements concerning the following code are true?() class a { public a() {} public a(int i) { this(); } } class b extends a { public boolean b(String msg) { return false; } } class c extends b { private c() { super(); } public c(String msg) { this(); } public c(int i) {} } A、The code will fail to compile.B、The constructor in a that takes an int as an argument will never be called as a result of constructing an object of class b or c.C、Class c has three constructors.D、Objects of class b cannot be constructed.E、At most one of the constructors of each class is called as a result of constructing an object of class c.
Which three demonstrate an “is a” relationship?() A、 public class X { } public class Y extends X { }B、 public interface Shape { } public interface Rectangle extends Shape{ }C、 public interface Color { } public class Shape { private Color color; }D、 public interface Species { } public class Animal { private Species species; }E、 public class Person { } public class Employee { public Employee(Person person) { }F、 interface Component { } class Container implements Component { private Component[] children; }
public class A extends Thread { A() { setDaemon(true); } public void run() { (new B()).start(); try { Thread.sleep(60000); } catch (InterruptedException x) {} System.out.println(“A done”); } class B extends Thread { public void run() { try { Thread.sleep(60000); } catch (InterruptedException x) {} System.out.println(“B done”); } } public static void main(String[] args) { (new A()).start(); } } What is the result?() A、 A doneB、 B doneC、 A done B doneD、 B done A doneE、 There is no exception that the application will print anything.F、 The application outputs “A done” and “B done”, in no guaranteed order.
class Top { static int x = 1; public Top(int y) { x *= 3; } } class Middle extends Top { public Middle() { x += 1; } public static void main(String [] args) { Middle m = new Middle(); System.out.println(x); } } 结果为:() A、1B、2C、3D、编译失败
Which the two demonstrate an “is a” relationship?()A、 public interface Person {} Public class Employee extends Person {}B、 public interface Shape {} public interface Rectangle extends Shape {}C、 public interface Color {} public class Shape { private Color color; }D、 public class Species {} public class Animal { private Species species; }E、 interface Component {} Class Container implements Component {private Component [] children;
Which two demonstrate an “is a” relationship?() A、 public interface Person { } public class Employee extends Person { }B、 public interface Shape { } public class Employee extends Shape { }C、 public interface Color { } public class Employee extends Color { }D、 public class Species { } public class Animal (private Species species;)E、 interface Component { } Class Container implements Component ( Private Component[ ]children; )
What produces a compiler error?() A、 class A { public A(int x) {} }B、 class A {} class B extends A { B() {} }C、 class A { A() {} } class B { public B() {} }D、 class Z { public Z(int) {} } class A extends Z {}
public class Starter extends Thread { private int x= 2; public static void main(String[] args) throws Exception { new Starter().makeItSo(); } public Starter() { x=5; start(); } public void makeItSo() throws Exception { join(); x=x- 1; System.out.println(x); } public void run() { x *= 2; } } What is the output if the main() method is rum?() A、 4B、 5C、 8D、 9E、 Compilation fails.F、 An exception is thrown at runtime.G、 It is impossible to determine for certain.
public class Parent { int change() {…} } class Child extends Parent { } Which methods can be added into class Child?() A、 public int change(){}B、 int chang(int i){}C、 private int change(){}D、 abstract int chang(){}
public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } Which two classes use the Shape class correctly?()A、 public class Circle implements Shape { private int radius; }B、 public abstract class Circle extends Shape { private int radius; }C、 public class Circle extends Shape { private int radius; public void draw(); }D、 public abstract class Circle implements Shape { private int radius; public void draw(); }E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
单选题public class TestSeven extends Thread { private static int x; public synchronized void doThings() { int current = x; current++; x = current; } public void run() { doThings(); } } Which is true?()A Compilation fails.B An exception is thrown at runtime.C Synchronizing the run() method would make the class thread-safe.D The data in variable “x” are protected from concurrent access problems.E Declaring the doThings() method as static would make the class thread-safe.F Wrapping the statements within doThings() in a synchronized(new Object()) {} block would make the class thread-safe.
多选题Which are syntactically valid statement at// point x?() class Person { private int a; public int change(int m){ return m; } } public class Teacher extends Person { public int b; public static void main(String arg[]){ Person p = new Person(); Teacher t = new Teacher(); int i; // point x } }Ai = m;Bi = b;Ci = p.a;Di = p.change(30);Ei = t.b.
多选题public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } Which two classes use the Shape class correctly?()Apublic class Circle implements Shape { private int radius; }Bpublic abstract class Circle extends Shape { private int radius; }Cpublic class Circle extends Shape { private int radius; public void draw(); }Dpublic abstract class Circle implements Shape { private int radius; public void draw(); }Epublic class Circle extends Shape { private int radius;public void draw() {/* code here */} }Fpublic abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
单选题class ClassA { public int numberOfinstances; protected ClassA(int numberOfinstances) { this.numberOflnstances = numberOfinstances; } } public class ExtendedA extends ClassA { private ExtendedA(int numberOfinstances) { super(numberOflnstances); } public static void main(String[] args) { ExtendedA ext = new ExtendedA(420); System.out.print(ext.numberOflnstances); } } Which is true?()A 420 is the output.B An exception is thrown at runtime.C All constructors must be declared public.D Constructors CANNOT use the private modifier.E Constructors CANNOT use the protected modifier.
多选题Which two demonstrate an “is a” relationship?()Apublic interface Person { } public class Employee extends Person { }Bpublic interface Shape { } public class Employee extends Shape { }Cpublic interface Color { } public class Employee extends Color { }Dpublic class Species { } public class Animal (private Species species;)Einterface Component { } Class Container implements Component ( Private Component[ ]children; )
单选题What produces a compiler error?()A class A { public A(int x) {} }B class A {} class B extends A { B() {} }C class A { A() {} } class B { public B() {} }D class Z { public Z(int) {} } class A extends Z {}
多选题public class TestDemo{ private int x = 2; static int y = 3; public void method(){ final int i=100; int j = 10; class Cinner{ public void mymethod(){ //Here } } } } 在Here处可以访问的变量是哪些?()AxByCiDj