JAVA · ОСНОВЫ · LESSON 20
Name upon creation
Designer · about 17 minutes
Learning with progressRead the summary for free. To save the work, log in to the account.
Type the code yourself
Type an example manually. Check the signs and brackets.
public class Main {
public static void main(String[] args) {
Cat cat = new Cat("Рыжик");
System.out.println(cat.name);
}
}
class Cat {
String name;
Cat(String newName) {
name = newName;
}
}Open the editor for class workSolve it yourself
Make a Dog class with a String name field and a Dog constructor (ZString newName), which retains the name. In main, create Dog with the name «Бим» and output dog.name.
The answer is hidden. Use similar examples from the lesson notes.
Opening up your homework