Advertisement
MrDoyle

13) Classes and Objects

Jan 14th, 2021
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. class Person{
  2.  
  3.     //Instance variables (data or "state")
  4.     String name;
  5.     int age;
  6.  
  7.     //Classes can contain
  8.  
  9.     // 1. Data
  10.     // 2. Subroutines (methods)
  11. }
  12.  
  13.  
  14. public class Main {
  15.  
  16.     public static void main(String[] args) {
  17.  
  18.         Person person1 = new Person();
  19.         person1.name = "Joe Bloggs";
  20.         person1.age = 37;
  21.  
  22.         Person person2 = new Person();
  23.         person2.name = "Sarah Smith";
  24.         person2.age = 20;
  25.  
  26.         System.out.println(person1.name);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement