NEW
Font size
Worksheetsjava Programming1
Total questions: 28
Worksheet time: 17mins
Java was developed by
James gosling
John gosling
James frank
John frank
Which of the following is the correct main() method signature in Java?
public static void main (String [] args)
public static void Main (String [] args)
public static void main (string [] args)
public static void main (String args)
Which of the following is a valid variable declaration in Java?
int 1myInteger = 0;
int int = 0;
Int my Integer = 0;
int myInteger = 0;
Which of this command does not have errors?
System.out.print("Hello World")
System.out.print(Hello World);
System.out.Print("Hello World);
System.out.print("Hello World");
What will be output of below program?
public class Test {
public static void main(String[] args) {
int x = 10*20-20;
System.out.println(x);
}
}
Runtime Error
Prints 180
Prints 0
None of the above
What is the output for the following statement:
System.out.print("1"+"1");
11
2
Error Message
Indicate the actual output of the statements below:
int thisYear = 2020;
System.out.println("The current year is "+thisYear);
The current year is thisYear
The current year is 2020
No output; an error exists
The current year is
Which of the following is used as a terminator in Java programming?
)
;
.
>
int x= 10;
int y = 20;
int z = x + y;
System.out.println(z);
Guess the output.
1020
10 20
30
"10 20"
what is the output of this question?
class Test1 {
public
static void main(String[] args)
{
int x = 20;
System.out.println(x);
}
static
{
int x = 10;
System.out.print(x + " ");
}
}
10 20
20 10
10 10
20 20
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 one of the following is a valid statement?
char[] c = new char();
char[] c = new char[5];
char[] c = new char(4);
char[] c = new char[];
The following Syntax is used for?
class Subclass-name extends Superclass-name
{
//methods and fields
}
Polymorphism
Encapsulation
Inheritance
None of the above
Which of these is correct way of inheriting class A by class B?
class B + class A {}
class B inherits class A {}
class B extends A {}
class B extends class A {}
Output of following Java program?
Base
Derived
Derived
Base
Base
Derived
Base
Derived
Base
Compiler Error
When saving a Java source file, save it with an extension of
.java.
.javac.
.src.
.class.
Which of the following is not a rule that must be followed when naming identifiers?
After the first character, you may use the letters a-z, A-Z, an underscore, a dollar sign, or digits 0-9.
Identifiers can contain spaces.
Uppercase and lowercase characters are distinct.
The first character must be one of the letters a-z, A-Z, an underscore or a dollar sign.
To print "Hello, world" on the monitor, use the following Java statement:
System.out.println("Hello, world");
System Print = "Hello, world";
SystemOutPrintln('Hello, world');
system.out.println{Hello, world};
Which of these statement is incorrect?
Every class must contain a main() method
Applets do not require a main() method at all
There can be only one main() method in a program
main() method must be made public
What is the extension of compiled java classes?
.java
.class
.txt
.js
Where does a java program start executing instructions from:
class
source file
main method
object
Which of these keywords is used to make a class?
class
struct
int
none of the mentioned
Which of the following is a type of polymorphism in Java?
Compile time polymorphism
Execution time polymorphism
Multiple polymorphism
Multilevel polymorphism
Which of the following is not OOPS concept in Java?
Inheritance
Encapsulation
Polymorphism
Compilation
