Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Basic  JAVA code for creating classes, objects, and methods and should birthday's be created as a string or a date?

Posted on 2004-11-08
3
Medium Priority
?
192 Views
Last Modified: 2013-11-23
Is this the correct syntax for creating a class, objects, and methods in Java


---For Defining a Class named Person and amethod named age

Class Person
     string Fname
     string Lname
     string Birthday

  int age ( )
    return Date – getJulian(Birthday)

-- For Defining 2 Objects named Employee and Student

Person Employee = new Person ( );  int e_age;
Person Student = new Person ( );  int s_age;

--- For assigning attributes values

Employee.Fname = ‘Sam’
Employee.Lname = ‘Brown’
Employee.Birthday = ’07/13/73’
e_age = Employee. age ( )

0
Comment
Question by:dlabraham
1 Comment
 

Accepted Solution

by:
arciledano earned 200 total points
ID: 12537571
To define the class: (Observe that classnames start with a capital, and by convention variables do not, you might also want to have a constructor which is called whenever you create an instance of the class. By default the Object-class' constructor is used).

class Person {
     String fName;
     String lName;
     String birthday;
     
     int age() {
          return(Date -  this.birthday); //  This refers to this instansiation of the class
     }
 
}
-----------------------------------------------------------------
Defining two objects: (Actually creating two objects as well)
Correct, except for the variable convention.

Person employee = new Person();
int e_age;
Person student = new Person();
int s_age;
-----------------------------------------------------------------
Assigning attribute values. Strings use double quotes (").

employee.fName = "Sam";
employee.fName = "Brown";
employee.birthday = "07/13/73";
e_age = employee.age( );
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Introduction to Processes
Screencast - Getting to Know the Pipeline

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question