Quick Index
Overview


Title Here
For this full example we'll have a little practice declaring variables
20=10*2
area width height


Problem 1




Write the Java program code to declare the following variables:

A variable named "width" of type "int"
A variable named "favIceCream" of type "String" Description


See the section "Declaration Examples" Tips

Hints

Solution


Problem 2



Write the Java program code to declare the following variables:

A variable named "large" of type "boolean"
A variable named "perimeter" of type "double" Description


See the section "More Data Types" Tips

Hints

Solution


Problem 3



We have coded a couple of our own classes/types. Declare variables of these types.

A variable named "p1" of type "Person"
A variable named "p2" of type "Person" Description


Coding is all about patterns. There is a simple pattern for declaring vars. Tips

Hints

Solution


Code



Java Code for Declarations
Here are the coded declarations.

Only worry about the code that is highlighted. We'll learn about the other code later. Just copy the other code as-is.

Note that these are not instance variables. They do not need the access modifier private or public.

Downloadable code here....
public class DeclaringVariables {

	public void declarations1() {
		//Declarations #1
		int width;
		String favIceCream;
	}

	public void declarations2() {
		//Declarations #2
		boolean large;
		double perimeter;
	}

	public void declarations3() {
		//Declarations #3
		Person p1;
		Person p2;
	}

}