T or F 1)If a class C is declared as abstract, then private C myC = new C(); is
ID: 3587880 • Letter: T
Question
T or F
1)If a class C is declared as abstract, then private C myC = new C(); is valid.
2)If the following statements are the only two statements in a method,
String X = new String(“thing one”); and String Y= new String(”thing one”); then
X.equals(Y) evaluates to true, but X == Y evaluates to false within that method.
3)int i = Math.sqrt(4.0); is a valid statement.
4)Consider the statement: String S = “Out of Gas”; then the statement:
S[7] = 'g'; will change “Gas” to “gas”.
5)Method declarations void A(double x, integer k){}; and
void A(integer k, double x) {}; have identical signatures
6)A class can implement multiple interfaces
7)The following is a legal statement: double x = 5;
8)Suppose you have the following declaration: int xyz = 4; Then, in the body of a switch statement block
case xyz: System.out.println(“4”);
break;
is legal.
9)Boolean primitive variables can only be assigned values: true, false, or null.
10)Any for loop can be rewritten using a while loop.
11)A variable declared as static cannot ever be modified, once it has been declared and initialized.
12)Consider the statement: throw new IllegalArgumentException(); This always causes the program to immediately exit.
13)It is legal to define more than one class in a java source file as long as only one of them is public.
14)If X is any valid, defined java object, then Object tmp=X; is a valid statement.
15)If a non abstract class A implements interface B, class A does not have to define all the methods in interface B. But if it doesn't class A cannot be instantiated.
16)Code that does not explicitly handle checked exceptions, results in a compilation error.
17)A class declared as final cannot be inherited via the extends keyword.
18)The binary search algorithm will work properly on all integer arrays.
19)(“Give me Liberty”.split(“ “).length) evaluates to 3
20)You can index into an array with a variable of type double as long as the there are no digits past the decimal point.
21)An instance variable declared as private can be seen only by the class in which it was declared and all its sub classes
22)“”.format(“%d %s ”,14, “shopping days left”); is a valid statement.
23)The declaration FilledOval[ ][ ] A = new FilledOval[20][30]; creates 600 FilledOval instances using the FilledOval() constuctor.
24)The constructor of the super class is only called when the constructor of the sub class explicitly calls super(); as its first line.
25)The protected keyword can only be applied to instance variables.
Explanation / Answer
Hi,
There are too many questions in this, please refrain from doing so, as this is against chegg policy, please post the second set as a different question, you will get your answer in minutes :)
1. FALSE, we cannot create instances of abstract classes, they are supposed to be used as parent class to other classes
2.TRUE, x.equals compares the values withing the implemented method from String class where == only compares instances
3.FALSE, this results in lossy conversion error, since sqrt returns a double which could be too long for an int.
4. FALSE, string cannot be accessed directly via indices, that is only possible with arrays
5. FALSE, the two methods have different signature, the input params of A are(double,integer) and B are(integer,double)
6.TRUE, this is the way by which multiple inheritance is posible in java
7.TRUE, its is automatically set as 5.0, if the type is defined as double
Please Thumbs up if this was helpful, otherwise let me know in comments
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.