Cerficacion java

Solo disponible en BuenasTareas
  • Páginas : 8 (1824 palabras )
  • Descarga(s) : 0
  • Publicado : 3 de noviembre de 2011
Leer documento completo
Vista previa del texto
1. - What will happen when you attempt to compile and run this code?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}

public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
publicvoid myfunc(){
System.out.println("My Func");
}
public void amethod(){
myfunc();
}
}
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.
2) The compiler will complain that the Base class has nonabstract methods
3) The code will compile but complain at run time that the Base class has non abstract methods
4) The compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it

2. - What will happen when you attempt to compile and run this code?
public class MyMain{
public static void main(String argv){
System.out.println("Hello cruelworld");
}
}
1) The compiler will complain that main is a reserved word and cannot be used for a class
2) The code will compile and when run will print out "Hello cruel world"
3) The code will compile but will complain at run time that no constructor is defined
4) The code will compile but will complain at run time that main is not correctly defined
In this example the parameter is astring not a string array as needed for the correct main method

3.- Which of the following are Java modifiers?

1) public
2) private
3) friendly
4) transient
5) vagrant
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.
4.- What will happen when you attempt to compile and run thiscode?
class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}

public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}

public void myfunc(){
System.out.println("My func");
}public void amethod(){
myfunc();
}
}
1) The code will compile and run, printing out the words "My Func"
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
3) The code will compile but complain at run time that the Base class has non abstract methods
4) The compilerwill complain that the method myfunc in the base class has no body, nobody at all to looove it
5.- Why might you define a method as native?
1) To get to access hardware that Java does not know about
2) To define a new data type such as an unsigned integer
3) To write optimised code for performance in a language such as C/C++
4) To overcome the limitation of the private scope of a method6.- What will happen when you attempt to compile and run this code?
class Base{
public final void amethod(){
System.out.println("amethod");
}
}

public class Fin extends Base{
public static void main(String argv[]){
Base b = new Base();
b.amethod();
}
}
1) Compile time error indicating that a class with any final methods must be declared finalitself
2) Compile time error indicating that you cannot inherit from a class with final methods
3) Run time error indicating that Base is not defined as final
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.

7.- What will happen when you attempt to compile and run...
tracking img