Hello, World! My name is Alex and i am a beginner in Java. I tried to create 2 simple objects from the same class and give them the values inputed from console( as string). Is this correct or it should be done in another particular manner? Also, the constructor asks for a String parameter ( "string x" has nothing to do as far as i know with the programm variables i use but the ide do not let me to compile other way...perhaps it has something to do with creating objects - constructor - I/O implementation , yet it should be a parameter formula like String a, String b ... well , i'm a noob) i am very open for suggestion. Thanks in advance ! alex
import java.util.Scanner;
public class ClassObject2 {
public ClassObject2(String x) {
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please insert a value for a: ");
String a = scan.nextLine();
System.out.println("Please insert a value for b: ");
String b = scan.nextLine();
ClassObject2 obj1 = new ClassObject2(a);
ClassObject2 obj2 = new ClassObject2(b);
System.out.println("object a has val.: " + a);
System.out.println("object b has val.: " + b);
}
}