Introduction to Java
Fill in the blanks with the correct words.
1. The int data type takes four bytes for storage.
2. ‘A’ is a character constant.
3. float a = 45.34; is a/an initialization statement.
4. The output of 20 % 6 in Java will be 2.
5. The do…while is an exit-controlled loop.
Write T for the true statement and F for the false one. Correct the false statement(s).
1. In Java, a class is a capsule of data members and member functions. (T)
2. To run a Java program, double-click the compiled class. (F) (Right-click the class and click void main() to execute it)
3. A variable name can start with a digit. (F) (A variable name can start with a letter or an underscore or a dollar sign)
4. The selection statements in Java are if and switch. (T)
5. The while loop is executed at least once. (F) (The do…while loop is executed at least once)
Choose the correct option.
1. Which data type is used to store a whole number?
a. float b. int c. double d. long double
2. Which of these is an invalid String constant?
a. “9” b. “Hello” c. ‘9’ d. “*****”
3. In the switch statement, if the value does not match any case label, then
a. Statements after break are executed
b. Statements in the default case are executed
c. An error occurs
d. None of these
4. Which of the following is a conditional statement?
a. for b. while c. if d. do…while
5. Which of these is not a valid initialization?
a. int a = 12; b. float b = 34.6 c. char a = ‘A’; d. String S = ‘Hello!’;
Answer the following.
1. What do you understand by object-oriented programming?
Object-oriented programming is a different and modern approach to programming that is based on the fundamental concept of objects.
2. What is a class in Java? What is it composed of?
A class is a collection of similar objects and acts as a data type for those objects. It is composed of data members and member functions.
3. What is a method? Explain its general format.
A method is a set of code that can be used at different points in the program.
1
2
3
<access specifier> <return type> <method name> (formal parameter list){
//body of the method
}
The access specifier can be public, protected, private or friendly.
The return type is the data type of the value returned by the method.
The method name is the name of the method.
The formal parameter list is the list of variables separated by commas that receive values when a method is called by the object.
4. What do you understand by data type? List the data types in Java.
Data type means the type of value that a variable can store. Following are the list of data types: byte, short, int long, char, float, double, boolean and String.
5. Name the three looping statements in Java. Write their syntax.
The three looping statements in Java are while, do…while, and for.
1
2
3
4
5
6
7
8
9
10
11
while(condition){
statement(s);
}
do{
statement(s);
}while(condition);
for(initialization; condition; update){
statement(s);
}
Comments
Post a Comment
This site is all about helping you kids study smart because for Gen Z, studying "hard" is not enough. If you feel there is any way I could improve my posts or if you have any random suggestion that might help make this more kid friendly, please don't hesitate to drop in a comment!
Be sure to check back for my response if you've asked me a question or requested a clarification through the comment section because I do make every effort to reply to your comments here.