Home > database >  What's the problem with my code? it runs but no output [closed]
What's the problem with my code? it runs but no output [closed]

Time:09-29

can you please help me with what's wrong with my code? It has no error and runs but it doesn't display the output. please help me revise it.

public class PersonType {

            private String firstName, lastName;
            
            public String getFirstName() {
                return firstName;
            }
            
            public String getLastName() {
                return lastName;
            }
            
            void print() {
                System.out.println(firstName " " lastName);
            }
            
            void setName(String first, String last) {
                firstName = first;
                lastName = last;
            }
            
            public PersonType() {
                setName(null, null);
            }
            
            public PersonType(String first, String last) {
                setName(first, last);
            }

        }

CodePudding user response:

So either you are not showing us the calling class or you simply forgot to add a main method. A possible way to generate output would be:

public static void main(String[] args) {
    new PersonType("Cy", "Car").print();
}

CodePudding user response:

try


    public static void main(String[] args) {
        new PersonType("Cy", "Car").print();
    }
  •  Tags:  
  • java
  • Related