Java Summary Question by hcj

VIEWS: 3 PAGES: 2

									Java Revision Answers - Part 1
1. What file extensions do our java source code files have? And what file extensions do our compiled java files have? Java source files have the extension .java Java compiled files have the extension .class 2. Write the line of code you would use to print “Hello World!” to the console. System.out.println(“Hello World!”); 3. What Class, and object does the println() method belong to? Class: System Object: out 4. Using the variables below, write a line of code that will print out the following, “My name is Jimmy and I am 50 years old”. You must use the variables in your answer. String name = “Jimmy”; int age = 50; System.out.println(“My name is “ + name + “ and I am “ + age + “ years old”); 5. Write the statements to declare a class called “HelloWorld”. public class HelloWorld { } 6. Write an empty main method. public static void main(String[] args) { } 7. Given code below highlight / circle the errors. static lowercase p Public class HelloWorld { public void main(String[] args) brace not bracket ( String name = Jimmy; System.out.println(“Hello World”; } closing brace { not opening brace There are 6 errors.

Missing quotes

No closing bracket

8. What is a class? A class is a template for an object, defining its characteristics (attributes) and behaviour (methods). 9. What is an object? An object is an instance of a class. methods of it's class. 10. List 4 data types. String, int, float, double, char, byte, short, long 11. Write a default constructor method for the Customer class. public Customer() { } 12. Where in a java class should you put statements to import java libraries? You should import java libraries outside (and preferably above) the class declaration. 13. In your own words write down what you think encapsulation means. Encapsulation means to hide data from the outside. It allows outside access to your hidden data through public methods / interfaces. It gives you control over what other people can do with your class data. Private data, public methods. 14. What does object referencing mean? An object variable does not store an object value. An object variable references an object value by storing the memory location of where the object value is being stored. 15. What is the difference between a private variable and a public variable? Private variables cannot be access directly from outside their class. A public method would be needed to access the private variable's value. Public variables can be accessed directly from outside their class. 16. List the three different types of variables we have discussed. instance fields, constants and class or static variables 17. What is the first bit of code that is run once we create a new object from a class? The constructor method It is manipulated by using


								
To top