what is/are true about the widgetCount variable? : Questions « Java Source And Data Type « SCJP






class MyClass {

}

class Widget extends MyClass {
  static private int widgetCount = 0;

  static synchronized int addWidget() {
    widgetCount++;
    return widgetCount;
  }

  int anotherMethod() {
    return widgetCount;
  }

}
   A. methods in the Widget class can access it.
   B. only the addWidget method can access it.
   C. If another class tries to access widgetCount, a runtime exception will be thrown.
   D. only methods in the Widget class and any derived classes can access it.








1.30.Questions
1.30.1.What is the output from the following code(array index)?
1.30.2.Answer: array index
1.30.3.Which of the following are true about this method declaration?
1.30.4.Answer: method declaration
1.30.5.Which of the following are true about this variable declaration?
1.30.6.Answer: variable declaration
1.30.7.What is the output from the following program?
1.30.8.Answer: static method and instance variable
1.30.9.What will be the result of trying to compile and run the following code?
1.30.10.Answer: main method
1.30.11.Select the correct command line to execute the program and produce "The word is gamma" as the output line.
1.30.12.Answer: main method parameter passin
1.30.13.Which of the following are not reserved words in Java?
1.30.14.Answer: reserved words in Java
1.30.15.What is the range of values that can be stored in a byte primitive variable?
1.30.16.Answer: range of values of a byte primitive variable
1.30.17.What is the range of values that can be stored in a long primitive?
1.30.18.Answer: range value for long primitive
1.30.19.Which of the following would be illegal identifiers for a Java variable?
1.30.20.Answer: identifiers for a Java variable
1.30.21.After the following code has been executed, what is the value of types[0]?
1.30.22.Answer: array element value
1.30.23.Which of the following class declarations are not correct Java declarations?
1.30.24.Answer: synchronized declaration
1.30.25.Which of the following declaration sets the proper access for MyAccess class in yourpackage package to not allow subclass?
1.30.26.Answer: package and subclass
1.30.27.what is/are true about the widgetCount variable?
1.30.28.Answer: static variable
1.30.29.File Derived.java contains the following classes, what will happen when this file is compiled?
1.30.30.Answer: derived class
1.30.31.What happens when you try to use multiple Widget objects in multiple Threads?
1.30.32.Answer: static variable(2)