3) error mine must be declared abstract
a class that contains an abstract method must itself be declared as abstract. it may however contain non abstract methods. any class derived from an abstract class must either define all of the abstract methods or be declared abstract itself.
3) one, two, default
code will continue to fall through a case statement until it encounters a break.
2) default, zero
although it is normally placed last the default statement does not have to be the last item as you fall through the case block. because there is no case label found matching the expression the default label is executed and the code continues to fall through until it encounters a break.
2,3
example 1 will not compile because if must always test a boolean. this can catch out c/c++ programmers who expect the test to be for either 0 or not 0.
3) no such file found, doing finally, -1
the no such file found message is to be expected, however you can get caught out if you are not aware that the finally clause is almost always executed, even if there is a return statement.
1) methods cannot be overriden to be more private
static methods cannot be overriden but they can be overloaded. if you have doubts about that statement, please follow and read carefully the link given to the sun tutorial below. there is no logic or reason why private methods should not be overloaded. option 4 is a jumbled up version of the limitations of exceptions for overriden methods
3) runtime exception
without the cast to sub you would get a compile time error. the cast tells the compiler that you really mean to do this and the actual type of b does not get resolved until runtime. casting down the object hierarchy is a problem, as the compiler cannot be sure what has been implemented in descendent classes. casting up is not a problem because sub classes will have the features of the base classes. this can feel counter intuitive if you are aware that with primitives casting is allowed for widening operations (ie byte to int).
1) system.out.println( -1 >>> 2);will output a result larger than 10
2) system.out.println( -1 >>> 2); will output a positive number
3) system.out.println( 2 >> 1); will output the number 1
you can test this with the following classm
public class shift{
static int i=2;
public static void main(string argv[]){
system.out.println( -1 >>> 2);
system.out.println( -1 >>> 2);
system.out.println( 2 >> 1);
}
}
java does not have a <<< operator. the operation 1 << 2 would output 4
because of the way twos complement number representation works the unsigned right shift operation means a small shift in a negative number can return a very large value so the output of option 1 will be much larger than 10.
the unsigned right shift places no significance on the leading bit that indicates the sign. for this shift the value 1 of the bit sign is replaced with a zero turning the result into a positive number for option 2.
4) compilation and output of either "vandaleur", "vandaleur 0", "vandaleur 0 1" "vandaleur 0 1 2" or "vandaleur 0 1 2 3"
if that seems a vauge answer it is because you cannot be certain of the system that the underlying os uses for allocating cycles for a thread. the chances are that once the thread has been spun off in the call to start in the method piggy the main method will run to completion and the value of sname will still be vandeluer before the thread modifies it. you cannot be certain of this though.
3) one button occupying the entire frame saying bye
the default layout manager for a frame is a border layout. if directions are not given (ie north, south, east or west), any button will simply go in the centre and occupy all the space. an additional button will simply be placed over the previous button. what you would probably want in a real example is to set up a flow layout as in
setlayout(new flowlayout());
which would allow the buttons to both appear side by side, given the appropriate font and size.
applets and panels have a default flowlayout manager
责任编辑:小草