Podcast
Questions and Answers
What is an array?
What is an array?
An array is a data structure that stores a collection of elements of the same data type in contiguous memory locations.
Clearly explain what each part of the method declaration below implies: public static void main(String args[])
Clearly explain what each part of the method declaration below implies: public static void main(String args[])
public
: This keyword means that the main
method is accessible from anywhere in the program.
static
: This keyword means the main
method is associated with the class itself, not with any particular object of the class. This allows the method to be called without creating an object of the class.
void
: This keyword means the main
method does not return any value.
main
: This is the name of the method. It is a special method that is the entry point for every Java program. The Java Virtual Machine (JVM) executes the code inside the main
method first when it runs a Java program.
(String args[])
: This is the parameter list for the main
method. It takes an array of strings as input. This array contains any command-line arguments that are passed to the Java program when it is executed.
How does Java achieve platform independence?
How does Java achieve platform independence?
Java achieves platform independence through its bytecode compilation mechanism. It compiles source code (.java) into bytecode (.class), which is platform-independent and can be run on any system that has a Java Virtual Machine (JVM).
Briefly discuss four key characteristics of Java.
Briefly discuss four key characteristics of Java.
Signup and view all the answers
What are the four access modifiers in Java?
What are the four access modifiers in Java?
Signup and view all the answers
Study Notes
CSC 2000 Computer Programming Final Exam
- Date: 19th November 2021
- Time: 09:00hrs - 12:00hrs
- Duration: 3 hours
- Venue: NSLT
-
Instructions:
- Two sections in the exam paper
- Java programming language only
- Answer all questions in Section A
- Choose three questions from section B
Section A - Short Answers (40 marks)
-
Question 1:
-
Part a: Write code for a
Polygon
base class with abstract methodsarea()
andperimeter()
. (3 marks) -
Part b: Write code for a
Triangle
class that extendsPolygon
with implementedarea()
andperimeter()
methods. (6 marks) -
Part c: Create
Isosceles
andEquilateral
triangle classes inheriting fromTriangle
with appropriate side relationships. (6 marks) -
Part d: Implement an
IllegalTriangleException
to ensure triangle side lengths satisfy the triangle inequality (sum of any two sides > third side). Modify the Triangle constructor to throw this exception. (5 marks)
-
Part a: Write code for a
-
Question 2:
- Part a: Define Object and Class. (4 marks)
-
Part b: Explain the parts of the
public static void main(String args[])
method declaration. (4 marks) - Part c: Describe Java's platform independence. (4 marks)
- Part d: Discuss four key characteristics of Java. (4 marks)
- Part e: List the four access modifiers in Java. (4 marks)
Section B (40 marks)
-
Question 1:
- Part a: Define an array. (2 marks)
- Part b: Describe how the class reads scores (0-100 or -1 to quit) from the keyboard. (4 marks)
- Part c: Store scores in one array and corresponding grades (A,B,C,D,F) in a parallel array. (6 marks)
- Part d: Implement a method to count the total number of each grade (A,B,C,D,F). (4 marks)
- Part e: Write a method to compute the average score and grade. (4 marks)
-
Question 2:
- Describe the classes (
Customer
,Toy
, and potentiallyChild
, their members (fields&methods), and write a Java program that meets the specifications.
- Describe the classes (
-
Question 3:
- Part a: Define a loop. (2 marks)
- Part b: Describe how conditions relate to loops. (2 marks)
Other Instructions / Content
-
Question 4:
- List Java primitive data types. (4 marks)
- Commands to compile & execute a
HelloWorld.java
file. (4 marks) - Rules for valid Java identifiers (3 marks)
- Naming conventions for classes, constants, and variables. (3 marks)
- Importance of code comments. (2 marks)
- Correctness of sample code provided. (4 marks)
-
Question 5:
- Illustrate state transitions in a Java thread. (6 marks)
- Define state and behavior in Java. (4 marks)
- Declare variables with access modifiers. (4 marks)
- Briefly explain different programming error types in Java. (6 marks)
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge of Java programming through this comprehensive final exam from CSC 2000. The quiz covers abstract classes, inheritance, and exception handling with a focus on geometry. Prepare to tackle questions related to polygons and triangles while demonstrating your coding skills.