Test de DSE

Descripción

simulador para segundo parcial de DSE
Jorge Enrique Macías Garza
Test por Jorge Enrique Macías Garza, actualizado hace más de 1 año
Jorge Enrique Macías Garza
Creado por Jorge Enrique Macías Garza hace casi 9 años
45
0

Resumen del Recurso

Pregunta 1

Pregunta
Which of the following statements are true?
Respuesta
  • An class is a blueprint for a object.
  • An object and a class are exactly the same.
  • An object is an instance of a class.
  • An attribute cannot be a reference to another object.

Pregunta 2

Pregunta
Given: class X { String str = "default"; X(String s) { str = s; } void print() { System.out.println(str); } public static void main(String[] args) { new X("hello").print(); } } What is the result?
Respuesta
  • hello
  • default
  • Compilation fails
  • The program prints nothing

Pregunta 3

Pregunta
Which two will compile, and can be run successfully using the command: java Fred1 hello walls. (Choose two)
Respuesta
  • class Fred1{ public static void main (String args) { System.out.println(args[1]);}}
  • class Fred1{ public static void main (String [] args) { System.out.println(args[2]);}}
  • class Fred1 { public static void main (String [] args) { System.out.println (args);}}
  • class Fred1 { public static void main (String [] args) { System.out.println (args [1]);}}

Pregunta 4

Pregunta
Consider the following program: class Point2D { private int x, y; public Point2D(int x, int y) { x = x; } public String toString() { return "[" + x + ", " + y + "]"; } public static void main(String[] args) { Point2D point = new Point2D(10, 20); System.out.println(point); } } Which one of the following options provides the output of this program when executed?
Respuesta
  • point
  • Point
  • [0, 0]
  • [10, 0]
  • [10, 20]

Pregunta 5

Pregunta
Which of the these are valid declarations of the main() method in the order to start the execution of a Java application?
Respuesta
  • static void main(String [] args){/* … */}
  • public static int main(String [] args){/*… */}
  • public static void main(String args){/*… */}
  • final public static void main(String [] arguments){/*… */}
  • public int main(String [] args, int argc){/*… */}
  • static public void main(String args []){/* … */}

Pregunta 6

Pregunta
Given: public static void main(String[] args) { double a = 2 + 5 * 6 / 7.0 % 6 + 7 - 9; System.out.println(a); } What is the result?
Respuesta
  • -2.0
  • 30.0
  • 4.2857
  • compilation fails

Pregunta 7

Pregunta
What will be result of attempting to compile this class? import java.util.*; package test; public class TestClass { public OtherClass oc = new OtherClass(); } class OtherClass { int value; }
Respuesta
  • The class will fail to compile, since the class OtherClass is used before it is defined.
  • There is no problem with the code.
  • The class will fail to compile, since the class OtherClass must be defined in a file called OtherClass.java
  • The class will fail to compile.
  • None of the above.

Pregunta 8

Pregunta
Given: public class SuperLoop3 { public static void main(String[] args) { int suma = 0; for (int i = 0, j = 9, z = 1; i < 4 && j > 0; i++, --j, j--) { do { suma += i * j % z + 3; } while (z++ <= 1); } System.out.println("suma:: " + suma); } } What is the result?
Respuesta
  • suma:: 22
  • suma:: 14
  • suma:: 20
  • compilation fails

Pregunta 9

Pregunta
Given: class Test { public static void main(String[] args) { int var = 3; switch (var) { case 1: try { throw new IllegalArgumentException(); } catch (RuntimeException e) { e.printStackTrace(); } default: try { throw new ArrayIndexOutOfBoundsException(); } catch (RuntimeException e) { e.printStackTrace(); } case 2: try { throw new ArithmeticException(); } catch (RuntimeException e) { e.printStackTrace(); } } } } What is the result?
Respuesta
  • java.lang.ArrayIndexOutOfBoundsException at com.bar.Test.main and java.lang.ArithmeticException at com.bar.Test.main at com.bar.Test.main
  • java.lang.ArrayIndexOutOfBoundsException at com.bar.Test.main
  • java.lang.ArithmeticException at com.bar.Test.main
  • compilation fails

Pregunta 10

Pregunta
Given: public class Foo { public static void main(String[] args) { int a = 10; long b = 20; short c = 30; System.out.println(++a + b++ * c); } }
Respuesta
  • 611
  • 641
  • 930
  • 960

Pregunta 11

Pregunta
class EJavaGuruStringBuilder { public static void main(String args[]) { StringBuilder ejg = new StringBuilder(10 + 2 + "SUN" + 4 + 5); ejg.append(ejg.delete(3, 6)); System.out.println(ejg); } } What is the output of the following code?
Respuesta
  • 12S512S5
  • 12S12S
  • 1025102S
  • Runtime exception
Mostrar resumen completo Ocultar resumen completo

Similar

Operadores Python
Giovanni Sanhuez
Mis Recursos de Programación
maya velasquez
FUNDAMENTOS DE REDES DE COMPUTADORAS
anhita
Editor Dibujo Paint
gladiscj
Herramientas de Software para Comercio y Finanzas
mishelleisabel
PROGRAMACIÓN ORIENTADA A OBJETOS - TERCER CORTE
Jose Anacona Pira
Parcial Fundamento de Programación
ALBERTO MANUEL PATERNINA LEON
Lenguaje de programación.
Lina Melo
FUNDAMENTOS DE BASES DE DATOS
Francisco Hernandez
Introducción a la Programación
Diego Benavides
Test sobre programación en ARDUINO
Santi tecnoprofe