ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Taller class design in java


Enviado por   •  22 de Julio de 2019  •  Trabajos  •  798 Palabras (4 Páginas)  •  168 Visitas

Página 1 de 4

Taller Class Design in Java        Ing. Matilde Montealegre Madero, MSc. Julio 10/19

Exercise 1. Constructors

package classdesign2019;

class Dog1 {

private String color;

public Dog1(String color) {

System.out.println("constructor");

this.color = color;

// A .What happened if the line this.color = color is

changed to color = color

}

public void printColor() {

System.out.println("color= " + color);

}

// B. What happened if next line is uncommented

// public dog() {}

// public void Dog() {} // not constructor since it has

return type

}

class Cat {

private String color;

private int height;

private int length;

public Cat(int length, int theHeight) {

//        length = this.length;

this.length = length;

height = theHeight;

}

public void printInfo() {

System.out.println("Cat length= " + this.length + "

height= " + height + " color= " + color);

}

}

public class ClassConstructors {

public static void main(String[] args) {

//C. Given the classes above create and instance of

class Dog1 that assign a color to a Dog and prints its

color.

//D. Create a white Cat with length 10 and height 12,

print the assignment

}

}

Exercise 2. Order of Initialization

//A. What is the order of initialization of following

code (explain)

package classdesign2019;

class Example {

private String name = "dog";

//private String name;

{

System.out.println(name);


}

private static int COUNT = 0;

static {System.out.println(COUNT);}

{

COUNT += 10;

System.out.println(COUNT);

}

public Example() {

System.out.println("constructor");

}

}

class Demo {

static {

add(2);

}

static void add(int number) {

System.out.print(number + " ");

}

Demo() {//constructor

...

Descargar como (para miembros actualizados)  txt (7.6 Kb)   pdf (75.1 Kb)   docx (17.7 Kb)  
Leer 3 páginas más »
Disponible sólo en Clubensayos.com