Question: The syntax to use the special type of for loop to process all elements of an array is ____. for statement (arrayName : dataType identifier)
The syntax to use the special type of for loop to process all elements of an array is ____.
|
| for statement (arrayName : dataType identifier) |
|
| for (dataType identifier : arrayName) statement |
|
| for statement (dataType identifier : arrayName) |
|
| for (arrayName : dataType identifier) statement |
The non-static methods of a class are called the ____ methods of the class.
|
| update |
|
| frozen |
|
| permanent |
|
| instance |
For reference type of variable, which statement is true about declaration of a variable and instantiation of the object?
|
| Declaration reserves memory location for the object and instantiation initializes the value. |
|
| Declaration reserves variable name with its type and instantiation creates the object. |
|
| They are the same. |
|
| A variable has to be instantiated before your can declare it. |
Which of the following is an example of a local identifier in the following code?
01: public class scopeRule 02: { 03: static double intRate = 0.055; 04: static String name; 05: static int t;
06: public static int main(String[] args) 07: { 08: int first; 09: double u, t; 10: String str; 11: //. . . 12: }
13: public static int first(int x, int y) 14: { 15: int t; 16: }
17: public static double salary; 18: }
|
| t (Line 15) |
|
| intRate (Line 3) |
|
| salary (Line 17) |
|
| name (Line 4) |
Which of the following identifiers in the following code are usable in method first?
01: public class scopeRule 02: { 03: private double intRate = 0.055; 04: private static String name; 05: private int t;
06: public static int main(String[] args) 07: { 08: int first; 09: double u, t; 10: String str; 11: //. . . 12: }
13: public static int first(int x, int y) 14: { 15: int t; 16: }
17: public double salary; 18: }
|
| Only salary (Line 17) |
|
| name (Line 4) |
|
| Both intRate (Line 3) and salary (Line 17) |
|
| Only intRate (Line 3) |
|
| first (Line 8) |
Which of the following identifiers in the following code are visible in another class?
01: public class scopeRule 02: { 03: private double intRate = 0.055; 04: private static String name; 05: private int t;
06: public static int main(String[] args) 07: { 08: int first; 09: double u, t; 10: String str; 11: //. . . 12: }
13: public static int first(int x, int y) 14: { 15: int t; 16: }
17: public double salary; 18: }
|
| first (Line 13) |
|
| intRate (Line 3) |
|
| salary (Line 17) |
|
| Both intRate (Line 3) and salary (Line 17) |
In the method first, the programmer wishes to update the value stored in the variable intRate (Line 3). Which of the following is correct?
01: public class scopeRule 02: { 03: private double intRate = 0.055; 04: private String name; 05: private static int t;
06: public static int main(String[] args) 07: { 08: int first; 09: double u, t; 10: String str; 11: //. . . 12: }
13: public static int first(int x, int y) 14: { 15: double intRate; 16: intRate = x * y; 17: }
18: public double salary; 19: }
|
| Write another non-static (instance) method to do so. |
|
| Update it in the method main (Line 6) |
|
| The code is correct. Nothing needs to be done. |
|
| Rename the variable on Line 15 to something else. |
A constructor that takes as a parameter an instance of the same class, .e.g.,
Abc x = new Abc(); // x is populated with some data Abc y = new Abc( x );
might be used for ______________?
|
| make an alias of the data in x |
|
| dual-use of x and y |
|
| Not a valid construct. |
|
| copy the data in x to the new object |
A class can only have one constructor.
|
| True |
|
| False |
If your class does not provide a default constructor, then your code will not execute.
|
| True |
|
| False |
The constructor of a class has a return type of Object.
|
| True |
|
| False |
The constructor of ClassA takes as a parameter an object reference of ClassB, i.e.,
public ClassA( ClassB obj ) { ... }
The programmer has written the following code in ClassB:
public ClassA someMethod() { return new ClassA( this ); }
Which of the following is true?
|
| The return type, ClassA is not valid in the header of someMethod. |
|
| Cannot use the keyword 'this' |
|
| Cannot create a new object in a return statement. |
|
| This code is valid. |
An object can exhibit polymorphism, i.e., be viewed in multiple ways. Because all object inherit (extend) from Object, a Person is an Object but ____________.
|
| it must provide a toString method |
|
| an Object is not necessarily a Person. |
|
| it cannot override the toString method in Object |
Consider the following class definition.
public class Cylinder extends Object { private double height;
public Cylinder (double radius, double h) { super(radius); height = h; } public double getRadius() { return super.getRadius(); }
public String toString() { return (getRadius() + " " + height); }
public double surfaceArea() { return 2 * 3.14 * getRadius() * height; }
public double volume() { return 3.14 * getRadius() * getRadius() * height; } }
Suppose that you have the following declaration.
Cylinder cyl = new Cylinder(1.5, 10);
Which of the following statements are valid in Java?
|
| cyl.surfaceArea(); |
|
| System.out.print(cyl.surfaceArea); |
|
| cyl.volume(); |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
