In a recent mock-exam that i attempted the following assertion was made:
String y = "test ";
String x;
assert(x > 1) : x = y + 1;
is this valid because x resolves to
test 1 (i.e a value) ?
and will the following assertion be valid
String test = null;
assert (x > 1) : test;
Another question tested the functionality of a private constructor:
Given the following:
class Parent{
private Parent(){
//Code
}
}
class Child extends Parent{
Child(){
//Code
}
}
Now if I, in some other context, try to instantiate a Child:
Child myChild = new Child();
I should get an error since the call to super(); won't be allowed, right ?
A followup to this. Is the only way to circumvent the above problem to either make an overloaded (non-private) constructor in Parent and then call that explicitly from the Child() constructor, or to simply remove the private, or are there other ways around this ?