CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
Madhu Prabha
Level 7
Gurgaon
  • 02.04.2020
  • 774views
  • 2comments

What is wrong with my code?

Question about the task Getters and setters for the Person class
Java Syntax,  Level 5,  Lesson 5
Under discussion

Create the Person class. A person should have a String name, int age, and char sex.
Create getters and setters for all the variables of the Person class.

Requirements:
  • The program must not read data from the keyboard.
  • The Person class must have a public static void main method.
  • The Person class should have 3 variables.
  • The Person class must have a String variable name.
  • The Person class must have an int variable age.
  • The Person class must have a char variable sex.
  • The class must have a setter for the variable name.
  • The class must have a getter for the variable name.
  • The class must have a setter for the variable age.
  • The class must have a getter for the variable age.
  • The class must have a setter for the variable sex.
  • The class must have a getter for the variable sex.
package com.codegym.task.task05.task0508; /* Getters and setters for the Person class */ public class Person { private String name; private int age; private char sex; public Person(String name, int age, char sex) { this.name=name; this.age=age; this.sex=sex; } public Person() { } public String getName(String name) { return name; } public void setName(String name) { this.name=name; } public int getAge(int age) { return age; } public void setAge(int age) { this.age=age; } public char getSex(char sex) { return sex; } public void setSex(char sex) { this.sex=sex; } public static void main(String[] args) { } }
0
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Misiu
Level 41 , Gdansk, Poland
2 April 2020, 14:05
Getters have no arguments. getSomething() { return something; }
+3
Madhu Prabha
Level 7 , Gurgaon, India
2 April 2020, 18:12
I see. Thanks :)
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.