answer 1)
1) the code will compile and run, printing out the words "my func"
a class that contains an abstract method must be declared abstract itself, but may contain non abstract methods.
answer 2)
4) the code will compile but will complain at run time that main is not correctly defined
in this example the parameter is a string not a string array as needed for the correct main method
answer 3)
1) public
2) private
4) transient
the keyword transient is easy to forget as is not frequently used. although a method may be considered to be friendly like in c++ it is not a java keyword.
answer 4)
2) the compiler will complain that the base class is not declared as abstract.
if a class contains abstract methods it must itself be declared as abstract
answer 5)
1) to get to access hardware that java does not know about
3) to write optimised code for performance in a language such as c/c++
answer 6)
4) success in compilation and output of "amethod" at run time.
a final method cannot be ovverriden in a sub class, but apart from that it does not cause any other restrictions.
answer 7)
4) compilation and execution without error
it would cause a run time error if you had a call to amethod though.
answer 8)
1)compile time error: base cannot be private
a top leve (non nested) class cannot be private.
answer 9)
4) p1 compiles cleanly but p2 has an error at compile time
the package statement in p1.java is the equivalent of placing the file in a different directory to the file p2.java and thus when the compiler tries to compile p2 an error occurs indicating that superclass p1 cannot be found.
answer 10)
2) an error at run time
this code will compile, but at run-time you will get an arrayindexoutofbounds exception. this becuase counting in java starts from 0 and so the 5th element of this array would be i[4].
remember that arrays will always be initialized to default values wherever they are created.
责任编辑:小草