Hi guys, I'm writing my end of year java exam tomorrow and only heard today that I'm supposed to learn about using multiple classes in java. Could someone please show me in general how to use multiple classes?
Also, in classes does the same rule apply as in methods whereby variables can only be used with a single method unless they're static?
What is the purpose of having multiple classes?
When running a method from another class do I go class_name.method_name(); ?
Thanks guys.
On a side note, how does the 'extends' thing work with classes?
I found this on wikipedia:
after the method Example2() runs does getData() run directly afterwards?
Also, in classes does the same rule apply as in methods whereby variables can only be used with a single method unless they're static?
What is the purpose of having multiple classes?
When running a method from another class do I go class_name.method_name(); ?
Thanks guys.
On a side note, how does the 'extends' thing work with classes?
I found this on wikipedia:
Code:
public class Example1
{
// This is a Java class, it automatically extends the class Object
public static void main (String args[])
{
System.out.println("Hello world!");
}
}
public class Example2 extends Example1
{
// This is a class that extends the class created in Example 1.
protected int data;
public Example2()
{
// This is a constructor for the class. It does not have a return type.
data = 1;
}
public int getData()
{
return data;
}
public void setData(int d)
{
data = d;
}
}
after the method Example2() runs does getData() run directly afterwards?