Font size
WorksheetsJava Tokens Identifiers Keyword
Total questions: 69
Worksheet time: 38mins
Which of these cannot be used for a variable name in java ?
Identifier & keyword
Identifier
Keyword
None of the mentioned
Which of these are selection statements in java
Break
Continue
For ( )
If ( )
Which statement is true about Java?
Java is a sequence-dependent programming language
Java is a code dependent programming language
Java is a platform-dependent programming language
Java is a platform-independent programming language
Which of these cannot be used for a variable name in Java?
identifier & keyword
identifier
keyword
none of the mentioned
What is the value of g?
int g = 3;
System.out.print(++g * 8);
(a)
Which of the following is not an OOPS concept in Java?
Polymorphism
Inheritance
Compilation
Encapsulation
StringBuffer s1 = new StringBuffer("Quiz");
StringBuffer s2 = s1.reverse();
System.out.println(s2);
Find the Output?
QuizziuQ
Quiz
ziuQQuiz
ziuQ
Select the valid statement.
char[] ch = new char(5);
char[] ch = new char[5];
char[] ch = new char();
char[] ch = new char[];
When is the object created with new keyword?
At run time
At compile time
Depends on the code
None
Identify the corrected definition of a package.
A package is a collection of editing tools
A package is a collection of classes
A package is a collection of classes and interfaces
A package is a collection of interfaces
Identify the keyword among the following that makes a variable belong to a class,rather than being defined for each instance of the class.
final
static
volatile
abstract
Identify the output of the following program.
String str = “abcde”; System.out.println(str.substring(1, 3));
abc
bc
bcd
cd
Identify the return type of a method that does not return any value.
int
void
double
None
Exception created by try block is caught in which block
catch
throw
final
none
Which of the following exception is thrown when divided by zero statement is executed?
NullPointerException
NumberFormatException
ArithmeticException
None
What is not type of inheritance?
Single inheritance
Double inheritance
Multiple inheritance
Hierarchical inheritance
Which of these keywords is used to refer to member of base class from a sub class?
super
native
this
None
Which statements are true?
Overriding can be achieved with static methods
Final marked methods can be overridden
Overloading is runtime.
Return type can change in case of Overloading.
Choose a correct statement about Java Interfaces?
Interface contains only abstract methods by default.
A Java class can implement multiple interfaces
An Interface can extend or inherit another Interface.
All the above
A Java Class inherits Constants and Methods of an Interface using ____ keyword.
implements
extends
import
none
What is the use of final keyword in Java?
When a class is made final, a sublcass of it can not be created.
When a method is final, it can not be overridden.
When a variable is final, it can be assigned value only once.
All of the above
Which of these keywords is used to manually throw an exception?
throws
thow
try
finally
Guess The Output
----------------------------
int $abc=10;
System.out.println($abc);
10
11
Error
13
How many Keywords in JAVA ?
32
42
40
50
Why Java is not 100% Object-oriented? Choose the Reasons Below !
Primitive Data Types
By Static Keyword
Data Processing
Annotations
When programming, you have to use Data Types. Which of the following refers to interfaces, classes, and arrays?
Primitive
Non-Primitive
Arrays
Boolean
Classes and interfaces use a certain type of data type. Which one is it?
Primitive
Non-primitive
Floating Point
None of the answers
What is the main difference between float and double data types?
4.1 is an example of float.
4.11 is an example of double.
Float consists of 8 bytes, and double consists of 4 bytes.
Float consists of 4 bytes, and double consists of 8 bytes.
What kind of data type is used for numbers?
Integer
String
Boolean
Floating Point
Java Tokens help the compiler. Which of the following is a type of Java Token?
Identifiers
Keywords
Operators
All of the answers.
What is a blueprint and determines how an object will behave?
Object
Method
Attribute
Class
0
Garbage value
Compilation error
Runtime error
Which declaration will throw an error?
double num = 8;
int averageGrade = 89.7;
boolean done = false;
String done = "true";
which of the these variables allowed in java.
Local Variables
Instance Variables
Static Variables
All the above
none of the above
sum is 1020
sum is 30
airthmetic error
40
30
20
10
-10
10
error
predict output
Could not find or load main class sample
Could not find or load main class Hai
printed Hai
file name class name must me same
At the end of this fragment of code what is r1.count value?
10
-5
6
7
8
predict output
10
5
error
predict the output
10
25
10 25
25 10
1,2
2,3
1,2,3
1,2,3,4
What is instance variable?
Instance variables are static variables within a class but outside any method
Instance variables are variables defined inside methods, constructors or blocks
Instance variables are variables within a class but outside any method
None of the mentioned
Which of these operators is used to allocate memory for an object?
malloc
alloc
new
assign
Is static is a keyword.
True
False
Scope of the local variable?
within function
outside function
within class
outside class
class A
{
byte a;
int b;
long c;
public static void main(String args[])
{
A obj=new A();
}
}
What is the size of the object obj in bytes?
11
12
13
14
static variables can be accessed without objects.
True
False
public class Test1
{
//non-instance variable or data member
static int a;
//member fn
public static void main (String args[])
{
//local variable
int b=20;
Test1 ob=new Test1();
a=10;
System.out.println((a+b));
ob.display();
System.out.print((a+b));
}
//member fn
void display()
{
int c=30;
Test1 obj=new Test1();
a=20;
}
}
30
30
30
50
30
40
30
20
class A
{
int a;
String b;
float c;
}
The above class contains (a) many instance variables
Predict the output of the following program.
class A{
int a=40;//non static
public static void main(String args[]){
System.out.println(a);
}
}
Compilation Error
40
0
None of the above
what is the output of this question?
class Test1 {
static int x = 10;
public
static void main(String[] args)
{
Test1 t1 = new Test1();
Test1 t2 = new Test1();
t1.x = 20;
System.out.print(t1.x + " ");
System.out.println(t2.x);
}
}
10 10
20 20
10 20
20 10
What is the output of this question?
class Test1 {
static int i = 1;
public static void main(String[] args)
{
for (int i = 1; i < 10; i++) {
i = i + 2;
System.out.print(i + " ");
}
}
}
3 6 9
3 6 9 …. 27
Error
none
What is the output of this question?
class Test1 {
static int i = 1;
public static void main(String[] args)
{
int i = 1;
for (Test1.i = 1; Test1.i < 10; Test1.i++) {
i = i + 2;
System.out.print(i + " ");
}
}
}
1 3 9
1 2 3 … 9
3 5 7 9 11 13 15 17 19
None
Which of the following variable is declared as static?
Home address of a particular Student
Account number of a Customer
Company name of all Employees in an Organization
Name of a Employee
Static variables belongs to an Object?
Yes
No
What is the output of the following code?
public class Demo
{
static int x=10;
int y =15;
public Demo()
{
x++;
y++;
}
public static void main(String[] args)
{
Demo d1= new Demo();
Demo d2= new Demo();
Demo d3= new Demo();
System.out.println(d3.x + " , " +d3.y);
}
}
13,15
13,16
13,18
10, 18
How would you declare a variable storing the tax rate?
int taxRate = 5.1;
taxRate = "5.1";
double taxRate = 5.1;
double taxRate = "5.1";
I do hereby declare thee Sir Tax Rate
How would you declare a variable storing a person's name?
string name = "Elroy";
name String = "Elroy";
String name = Elroy;
String name = "Elroy";
Me llamo Elroy
How would you declare a variable that tells you that someone passed a class?
boolean passed = 'true';
boolean passed = true;
passed = true;
String passed = "true";
Trick question - no one passes this class
Which declaration will throw an error?
double num = 8;
int averageGrade = 89.7;
boolean done = false;
String done = "true";
What prints out "I love Java" successfully?
System.out.println(I love Java);
Systemoutprintln("I love Java);
System.out.println("I love" + " Java");
System.out.println("I love Java")
What is love? Baby dont hurt me. Dont hurt me. No more.
Which function is used to input int value in Java using Scanner class?
scanner_object . nextInteger( )
scanner_object . nextInt( )
scanner_object . nextint( )
scanner_object . NextInt( )
Which function is used to input float value in Java using Scanner class?
scanner_object . nextFloat( )
scanner_object . nextInt( )
scanner_object . nextfloat( )
scanner_object . NextFloat( )
What data type would you use for storing the average test score in a class?
double
String
int
char
Which company owns Java?
Oracle
Microsoft
Apple
Intel
The average salary of a Java developer in the USA?
$23,975
$43,975
$63,975
$83,975
Is Android based on Java?
True
False
What was Java originally designed for?
Interactive TV
Internet
Gaming
Cars
