Core - Defining Classes and Creating Objects
Core - Defining Classes and Creating Objects
Java
By the end of this video you will be able to…
▪Motivate the use of classes and objects in programming
▪Write classes in Java
▪Create objects and call methods on them
▪Describe what member variables, methods and
constructors are
Computer Science is…
The science of using and processing
large amounts of information
to automate useful tasks
and learn about the world around us
(using a computer)
Map
Shape
Location
Color
Window
… and plenty more objects
A class is a type of data
System.out.println(ucsd.distance(lima));
}
}
public class LocationTester
{
public static void main(String[] args)
{
SimpleLocation ucsd =
new SimpleLocation(32.9, -117.2);
SimpleLocation lima =
new SimpleLocation(-12.0, -77.0);
System.out.println(ucsd.distance(lima));
}
}
public class SimpleLocation
{
public double latitude;
public double longitude;
System.out.println(ucsd.distance(lima));
}
}
public class SimpleLocation
{
public double latitude;
public double longitude;
System.out.println(ucsd.distance(lima));
}
}
% javac *.java
% java LocationTester
6567.659