SlideShare a Scribd company logo
1 of 6
Exercise - Get familiar with common syntax errors
1. Delete a semicolon. Compile.
--- ‘;’ expected
2. Invoked a method, i.e., jump(), which is not defined. Compile.
--- cannot find symbol - method jump() :
3. Add turn(1, 2) to the code. Compile.
--- turn(int) in Animal cannot be applied to (int,int). Required:int; Found: int,int; reason:
actual and formal argument list differ in length
4. Add turn(4.5) to the code. Compile.
--- incompatible types: possible lossy conversion from double to int
5. Change to public double act(). Compile.
--- act() cannot override act() in Animal; return type double is not compatible with void
6. Change to public voids act(). Compile.
--- cannot find symbol - class voids
7. Change to public Turtle extends Actor. Compile.
--- class, interface, or enum expected
8. Delete right parenthesis: public void act(. Compile.
--- illegal start of type
9.Delete right parenthesis: move(;. Compile.
---illegal start of expression
Quiz
For each of the method signatures below, answer the following questions:
a. What is the method name?
b. Does the method return a value? If yes, what is the type of the return value?
c. How many parameters does the method have
d. Write the method call for the method signature. (How would you call the method in your
code?)
1. 1. public void eat()
a.
b.
c.
d.
2. public void setSize(int sze)
a.
b.
c.
d.
3. public boolean isGreater(int number)
a.
b.
c.
d.
4. Write a method signature for a method named "randomMove". The method has no
parameters, and it does not return a value.
5. Explain how you can tell the difference between a command method and a question
method:
6. Explain the difference between a class and an object:
7. What is a subclass and what does it inherit?
Quiz:
1. Which of these is the correct way to write a comment that stops at the end of the line?
a. /*
b. **
c. */
d. //
2. Which of these is a method for writing comments that go over a number of lines?
a. /*, *, *, */
b. //, /*, */, //
c. **, *, *, **
d. /*, /*, /*, /*
3. In the following sequence of code, what is being done?
super(20,20,10);
setBackground("grasstile.jpg");
populate();
a. set up the grid with grasstile.jpg background and add Spider objects
b. set up the grid with any background and define a function called populate
c. set up the grid, set the background, drag objects onto the background
d. set up the grid with grasstile.jpg background and run the populate function
4. Which two of these are correct ways to set up two variables: x and y, where two numbers can be
stored until needed?
a. x,y;
b. int x; int y;
c. int x; y;
d. int x,y;
5. The following code has an error, what is it?
public BugWorld() //constructor for BugWorld
{
super(30,20,20);
setBackground("grassPic.jpg")
populate();
}
a. one missing semi-colon
b. one missing curly bracket
c. two missing semi-colons
d. two missing curly brackets
Quiz:
1. What happens when you compile a Greenfoot program?
A. the code you have entered is spell-checked
B. the code you have entered is deleted
C. the code you have entered is copied to a separate disk
D. the code you have entered is translated into machine code
2. In the code below, what will go between the curly brackets?
public class Ant extends Actor
{
}
A. just an Act function for an Ant
B. all the code instructions for an Ant object
C. all the code instructions for every Actor object
D. just a constructor function for an Ant
3. What is the name for the function that sets up a world, or other, object when it is first introduced to
the game?
A. NewWorld
B. terminator
C. act
D. constructor
4. Which of these is a heading for a constructor function?
A. public void Act()
B. public void BugWorld()
C. public BugWorld()
D. public World()
Quiz:
1.The following questions refer to the code below:
public void moveForwardOrBack(boolean isScared)
{
if (isScared)
{
move(-4);
} else {
move(4);
}
}
1) In the code above, isScared is a...
a. method with a boolean return type
b. boolean expression
c. literal boolean value
d. parameter with a boolean data type
2) Draw the flowchart of moveForwardOrBack method
2. The following questions refer to the code below:
int bonus, sales = 10000;
if (sales < 5000)
{ bonus = 200; }
else if (sales < 7500)
{ bonus = 500; }
else if (sales < 10000)
{ bonus = 750; }
else if (sales < 20000)
{ bonus = 1000; }
else
{ bonus = 1250; }
1) What will be the value of bonus after the code above is executed?
a. 200 b. 500 c. 750 d. 1000 e. 1250
2) Draw the flowchart of the code above
Quiz
1. Match the following words with their definitions:
object
compiler
class
signature
Actor
source code
method
instantiate
type
machine code
void
parameter
____
____
____
____
____
____
____
____
____
____
____
____
a. nothing
b. the kind of data, such as boolean or int
c. an instance of a class
d. objects that can be placed into a world
e. a blueprint for making objects
f. the return type, method name, and parameter list
g. a list of inputs to a method
h. a direction or a question given to an instance
i. directions we write to the computer
j. directions the computer understands
k. a program that changes source code into machine code
L. the process of creating a new object
2. Given the following variable declarations, evaluate the following Boolean expressions:
int a= 7;
int b = 12;
int c = 12;
int d = 7;
1. (a ==c ||a ==b) _________
2. (a==b && c==d) _________
3. (a == b && b==c) _________
4. (a==c) _________
3. The following questions are about making the Ball’s image animate
a. Declare two instance variables to store the two different Greenfoot Images
b. Write a constructor that stores the image files and sets the current image to one of them
c. Write the method switchImage that switches from one image to the other
4. When do you use = and when do you use == in Java?
Quiz
1. Complete this for loop that would create 5 different Worms automatically and place them in
random locations in the world.
int i=0;
while (i <____) {
addObject( new ball(), Greenfoot.getRandomNumber(getWidth()),
Greenfoot.getRandomNumber(getHeight() );
i++;
}
2. What is the value of x at the end:
int i=0;
int x=0;
while (i < 4)
{ x = x + i;
i++;
}
A. 1 B. 2 C. 3 D. 4 E. 6
3. Given the following code, the output will be:
int i = 1;
int limit = 3;
while (i <= limit)
{
System.out.println(i);
i = i + 1;
}
A. 1
2
3
B. 1
2
3
4
C. 1 2 3
D. 1 2 3 4
4. What is the output of the following code?
int LIMIT = 4;
int sum = 0;
while (i <= LIMIT)
{ sum = sum + i; i = i + 1; }
System.out.println(sum);
A. 10
B. 9
C. 11
D. 8

More Related Content

What's hot

C Programming Language
C Programming LanguageC Programming Language
C Programming LanguageRTS Tech
 
Sample Paper 2 Class XI (Computer Science)
Sample Paper 2 Class XI (Computer Science)Sample Paper 2 Class XI (Computer Science)
Sample Paper 2 Class XI (Computer Science)Poonam Chopra
 
Develop Embedded Software Module-Session 3
Develop Embedded Software Module-Session 3Develop Embedded Software Module-Session 3
Develop Embedded Software Module-Session 3Naveen Kumar
 
Develop Embedded Software Module-Session 2
Develop Embedded Software Module-Session 2Develop Embedded Software Module-Session 2
Develop Embedded Software Module-Session 2Naveen Kumar
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and OperatorsSunil OS
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomeshpraveensomesh
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans incnayakq
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingRTS Tech
 
C interview questions
C interview questionsC interview questions
C interview questionsSoba Arjun
 

What's hot (16)

C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
C Programming Language
C Programming LanguageC Programming Language
C Programming Language
 
Core java
Core javaCore java
Core java
 
Sample Paper 2 Class XI (Computer Science)
Sample Paper 2 Class XI (Computer Science)Sample Paper 2 Class XI (Computer Science)
Sample Paper 2 Class XI (Computer Science)
 
7
77
7
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
 
Aptitute question papers in c
Aptitute question papers in cAptitute question papers in c
Aptitute question papers in c
 
Develop Embedded Software Module-Session 3
Develop Embedded Software Module-Session 3Develop Embedded Software Module-Session 3
Develop Embedded Software Module-Session 3
 
Develop Embedded Software Module-Session 2
Develop Embedded Software Module-Session 2Develop Embedded Software Module-Session 2
Develop Embedded Software Module-Session 2
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
 
random test
random testrandom test
random test
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
C interview questions
C interview questionsC interview questions
C interview questions
 

Similar to Java level 1 Quizzes

Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And AnswerJagan Mohan Bishoyi
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answersAkash Gawali
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2Knowledge Center Computer
 
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13Chris Ohk
 
CBSE XI COMPUTER SCIENCE
CBSE XI COMPUTER SCIENCECBSE XI COMPUTER SCIENCE
CBSE XI COMPUTER SCIENCEGautham Rajesh
 
Modify the bouncing ball example demonstrated/tutorialoutlet
Modify the bouncing ball example demonstrated/tutorialoutletModify the bouncing ball example demonstrated/tutorialoutlet
Modify the bouncing ball example demonstrated/tutorialoutletCleasbyz
 
Redo midterm
Redo midtermRedo midterm
Redo midtermIIUM
 
Dotnet unit 4
Dotnet unit 4Dotnet unit 4
Dotnet unit 4007laksh
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guidekrtioplal
 
Gsp 215 Enhance teaching-snaptutorial.com
Gsp 215 Enhance teaching-snaptutorial.comGsp 215 Enhance teaching-snaptutorial.com
Gsp 215 Enhance teaching-snaptutorial.comrobertleew18
 
Gsp 215 Believe Possibilities / snaptutorial.com
Gsp 215  Believe Possibilities / snaptutorial.comGsp 215  Believe Possibilities / snaptutorial.com
Gsp 215 Believe Possibilities / snaptutorial.comStokesCope20
 
Gsp 215 Exceptional Education / snaptutorial.com
Gsp 215  Exceptional Education / snaptutorial.comGsp 215  Exceptional Education / snaptutorial.com
Gsp 215 Exceptional Education / snaptutorial.comBaileya55
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professionalIsabella789
 
GSP 215 Education Organization - snaptutorial.com
GSP 215  Education Organization - snaptutorial.comGSP 215  Education Organization - snaptutorial.com
GSP 215 Education Organization - snaptutorial.comdonaldzs192
 

Similar to Java level 1 Quizzes (20)

Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
 
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
 
CBSE XI COMPUTER SCIENCE
CBSE XI COMPUTER SCIENCECBSE XI COMPUTER SCIENCE
CBSE XI COMPUTER SCIENCE
 
C++ Question
C++ QuestionC++ Question
C++ Question
 
CBSE 12 ip 2018 sample paper
CBSE 12 ip 2018 sample paperCBSE 12 ip 2018 sample paper
CBSE 12 ip 2018 sample paper
 
Modify the bouncing ball example demonstrated/tutorialoutlet
Modify the bouncing ball example demonstrated/tutorialoutletModify the bouncing ball example demonstrated/tutorialoutlet
Modify the bouncing ball example demonstrated/tutorialoutlet
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 
Dotnet unit 4
Dotnet unit 4Dotnet unit 4
Dotnet unit 4
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
Java Programming.pdf
Java Programming.pdfJava Programming.pdf
Java Programming.pdf
 
Gsp 215 Enhance teaching-snaptutorial.com
Gsp 215 Enhance teaching-snaptutorial.comGsp 215 Enhance teaching-snaptutorial.com
Gsp 215 Enhance teaching-snaptutorial.com
 
Revision1 C programming
Revision1 C programmingRevision1 C programming
Revision1 C programming
 
Gsp 215 Believe Possibilities / snaptutorial.com
Gsp 215  Believe Possibilities / snaptutorial.comGsp 215  Believe Possibilities / snaptutorial.com
Gsp 215 Believe Possibilities / snaptutorial.com
 
C test
C testC test
C test
 
Gsp 215 Exceptional Education / snaptutorial.com
Gsp 215  Exceptional Education / snaptutorial.comGsp 215  Exceptional Education / snaptutorial.com
Gsp 215 Exceptional Education / snaptutorial.com
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional
 
GSP 215 Education Organization - snaptutorial.com
GSP 215  Education Organization - snaptutorial.comGSP 215  Education Organization - snaptutorial.com
GSP 215 Education Organization - snaptutorial.com
 

Java level 1 Quizzes

  • 1. Exercise - Get familiar with common syntax errors 1. Delete a semicolon. Compile. --- ‘;’ expected 2. Invoked a method, i.e., jump(), which is not defined. Compile. --- cannot find symbol - method jump() : 3. Add turn(1, 2) to the code. Compile. --- turn(int) in Animal cannot be applied to (int,int). Required:int; Found: int,int; reason: actual and formal argument list differ in length 4. Add turn(4.5) to the code. Compile. --- incompatible types: possible lossy conversion from double to int 5. Change to public double act(). Compile. --- act() cannot override act() in Animal; return type double is not compatible with void 6. Change to public voids act(). Compile. --- cannot find symbol - class voids 7. Change to public Turtle extends Actor. Compile. --- class, interface, or enum expected 8. Delete right parenthesis: public void act(. Compile. --- illegal start of type 9.Delete right parenthesis: move(;. Compile. ---illegal start of expression Quiz For each of the method signatures below, answer the following questions: a. What is the method name? b. Does the method return a value? If yes, what is the type of the return value? c. How many parameters does the method have d. Write the method call for the method signature. (How would you call the method in your code?) 1. 1. public void eat() a. b. c. d. 2. public void setSize(int sze) a. b. c.
  • 2. d. 3. public boolean isGreater(int number) a. b. c. d. 4. Write a method signature for a method named "randomMove". The method has no parameters, and it does not return a value. 5. Explain how you can tell the difference between a command method and a question method: 6. Explain the difference between a class and an object: 7. What is a subclass and what does it inherit? Quiz: 1. Which of these is the correct way to write a comment that stops at the end of the line? a. /* b. ** c. */ d. // 2. Which of these is a method for writing comments that go over a number of lines? a. /*, *, *, */ b. //, /*, */, // c. **, *, *, ** d. /*, /*, /*, /* 3. In the following sequence of code, what is being done? super(20,20,10); setBackground("grasstile.jpg"); populate(); a. set up the grid with grasstile.jpg background and add Spider objects b. set up the grid with any background and define a function called populate
  • 3. c. set up the grid, set the background, drag objects onto the background d. set up the grid with grasstile.jpg background and run the populate function 4. Which two of these are correct ways to set up two variables: x and y, where two numbers can be stored until needed? a. x,y; b. int x; int y; c. int x; y; d. int x,y; 5. The following code has an error, what is it? public BugWorld() //constructor for BugWorld { super(30,20,20); setBackground("grassPic.jpg") populate(); } a. one missing semi-colon b. one missing curly bracket c. two missing semi-colons d. two missing curly brackets Quiz: 1. What happens when you compile a Greenfoot program? A. the code you have entered is spell-checked B. the code you have entered is deleted C. the code you have entered is copied to a separate disk D. the code you have entered is translated into machine code 2. In the code below, what will go between the curly brackets? public class Ant extends Actor { } A. just an Act function for an Ant B. all the code instructions for an Ant object C. all the code instructions for every Actor object D. just a constructor function for an Ant 3. What is the name for the function that sets up a world, or other, object when it is first introduced to the game? A. NewWorld B. terminator C. act D. constructor 4. Which of these is a heading for a constructor function? A. public void Act() B. public void BugWorld() C. public BugWorld()
  • 4. D. public World() Quiz: 1.The following questions refer to the code below: public void moveForwardOrBack(boolean isScared) { if (isScared) { move(-4); } else { move(4); } } 1) In the code above, isScared is a... a. method with a boolean return type b. boolean expression c. literal boolean value d. parameter with a boolean data type 2) Draw the flowchart of moveForwardOrBack method 2. The following questions refer to the code below: int bonus, sales = 10000; if (sales < 5000) { bonus = 200; } else if (sales < 7500) { bonus = 500; } else if (sales < 10000) { bonus = 750; } else if (sales < 20000) { bonus = 1000; } else { bonus = 1250; } 1) What will be the value of bonus after the code above is executed? a. 200 b. 500 c. 750 d. 1000 e. 1250 2) Draw the flowchart of the code above Quiz
  • 5. 1. Match the following words with their definitions: object compiler class signature Actor source code method instantiate type machine code void parameter ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ a. nothing b. the kind of data, such as boolean or int c. an instance of a class d. objects that can be placed into a world e. a blueprint for making objects f. the return type, method name, and parameter list g. a list of inputs to a method h. a direction or a question given to an instance i. directions we write to the computer j. directions the computer understands k. a program that changes source code into machine code L. the process of creating a new object 2. Given the following variable declarations, evaluate the following Boolean expressions: int a= 7; int b = 12; int c = 12; int d = 7; 1. (a ==c ||a ==b) _________ 2. (a==b && c==d) _________ 3. (a == b && b==c) _________ 4. (a==c) _________ 3. The following questions are about making the Ball’s image animate a. Declare two instance variables to store the two different Greenfoot Images b. Write a constructor that stores the image files and sets the current image to one of them c. Write the method switchImage that switches from one image to the other 4. When do you use = and when do you use == in Java? Quiz 1. Complete this for loop that would create 5 different Worms automatically and place them in random locations in the world. int i=0; while (i <____) { addObject( new ball(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight() ); i++; } 2. What is the value of x at the end: int i=0; int x=0; while (i < 4) { x = x + i; i++; }
  • 6. A. 1 B. 2 C. 3 D. 4 E. 6 3. Given the following code, the output will be: int i = 1; int limit = 3; while (i <= limit) { System.out.println(i); i = i + 1; } A. 1 2 3 B. 1 2 3 4 C. 1 2 3 D. 1 2 3 4 4. What is the output of the following code? int LIMIT = 4; int sum = 0; while (i <= LIMIT) { sum = sum + i; i = i + 1; } System.out.println(sum); A. 10 B. 9 C. 11 D. 8