I could not figure out whats wrong with the below code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I could not figure out whats wrong with the below code

public class Cat { String name; int age; public static void main(String[] args) { Cat smudge = new Cat(); System.out.println("Here the program does something for 2 hours..."); smudge.age = 3; smudge.name = "Smudge"; } } Look over this code and try to figure out what's wrong with our program. Our program had a cat with no name or age for 2 hours! I did understand the above statement

26th Jun 2020, 11:29 AM
stephen haokip
stephen haokip - avatar
3 Answers
0
The original article says something is wrong with the code
26th Jun 2020, 11:59 AM
stephen haokip
stephen haokip - avatar
0
Its from codegym
26th Jun 2020, 12:04 PM
stephen haokip
stephen haokip - avatar
0
there are many Cat statements, perhaps you are solving this: "Create valid cats in an unnatural way: using constructors. Let's create a Cat class and declare five different constructors. The simplest constructor contains one parameter: name. The next has name and age. And we'll add weight to the third. Read about the rest in the task conditions." so learn what constructor of object in java is
27th Jun 2020, 2:21 AM
zemiak