Universidad Surcolombiana: Main Parameters, Overloaded Main
Universidad Surcolombiana: Main Parameters, Overloaded Main
INGENIERIA DE SOFTWARE
NEIVA
HUILA
2020-1
/*
* NOW overloaded main : overloaded methods are
methods with the same name but
* different signature. Use the following methods
main in the class. Verify if
* these main methods can be used.
*/ Read handout 1: Java Building blocks from page 18 to 41
/* and do the following.
* public static void main(String args)
{ System.out.println("Hello Exam 2"); } Exercise 1. Constructors
*/ package classdesign2019;
/* class Dog1 {
* Both main(String[]) and main(String...) can not be private String color;
declared in same file.java public Dog1(String color) {
*/ System.out.println("constructor");
// signature for main this.color = color;
//public static void main(String[] args){} // A .What happened if the line this.color = color is
//static public void main(String[] args) {} changed to color = color
//public static void main(String[] args) {} }
public static void main(String args) { public void printColor()
System.out.println("List of Arguments " + { System.out.println("color= " + color);}
args); /**
} * RTA: La asignación de la variable no tiene
efecto para ser invocada.
public static void main(int number) { */
System.out.println("Hello exam parameter // B. What happened if next line is uncommented
integer is = " + number);
// public dog() {}
main("Hello + World + Overloading + main "
/**
+ 3 + " " + 5);
* RTA: Error porque se necesita que el método
}
retorne algo o sino que sea void
}// End of class
*/
// 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
}
}