WorksheetsBasics of OOP with JAVA
Total questions: 25
Worksheet time: 20mins
When is the object created with new keyword?
At compile time
At run time
Depends on the code
At execution time
Java is a platform independent programming language
True
False
What is a correct difference between print() and println()?
print() prints the output and move to new line, println() prints the output and stays on same line
print() prints the output and stays on same line, println() prints the output and move to new line
None of the given
Both of the given
What is the problem with this code?
Line 1: String myName = "Luna";
Line 2: System.out.println ("My name is " + myname);
Line 2: should be System.out.println ("My name is myName");
Line 2: should be System.out.println ("My name is "+ myName);
Line 2: should be System.out.display("My name is " + myname);
There is no problem with the code
Which of these cannot be used for a variable name in java ?
Identifier & keyword
Identifier
Keyword
None of the mentioned
Is the process by which one object can acquire the properties of another object.
Polymorphism
Inheritance
Encapsulation
Object-Oriented Programming
A ___________ file is created after successful compilation of a Java program.
Object file
Array file
Class file
String file
Which of the following is a part of Java Development Kit?
Java runtime environment
Java Development kit
Java Virtual Machine
All of them
A Java file with extension .class contains
Java source code
HTML Tags
Java Bytecodes
A program file written in java programming language
Which of the following is not a primitive data type of JAVA?
int
char
String
float
Scanner inp= new Scanner(System.in);
What is System.in in this declaration?
Any file storing data
Reference to standard input device, that is, keyboard
Reference to a scanner as an input device
It is a mouse as an input device
Polymorphism related to :
PPO
Class
OPP
OOP
Which from the following is a feature that allows us to perform a single action in different ways.
Abstraction
Polymorphism
Encapsulation
Inheritance
The process by which objects of one class acquire the properties of objects of another class is known as
Polymorphism
Inheritance
Data Hiding
Association
Hiding complexity can also be termed as
Inheritance
Overloading
Data hiding
Abstraction
Father of Java
Dennis Ritchie
James Gosling
Bill Joy
Bjarne Stroustrup
What is the file extension for Java Source Code?
.java
.class
.exe
.obj
Find the output for the following.
public class IncDec
{
public static void main(String s[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
}
}
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";
System.out.println(sup);
}
}
small
tiny
huge
Compilation fails
What is the value of y after evaluating the expression given below?
y += ++y + y–– + ––y; when int y=8
(a)
How many times is "HI!" printed?
15
12
10
8
Infinite Loop
A SWITCH fall through occurs in Java only in the absence of ___.
Keyword "case"
Keyword "break"
Keyword "default"
None of these
What is the output of the below Java program with a SWITCH statement?
int points=6;
switch(points)
{
case 6: ;
case 7: System.out.print("PASS");
case 8: ;
case 9: System.out.print(" Excellent");
case 10: System.out.print(" Outstanding"); break;
default: System.out.print("FAIL");
}
PASS Excellent Outstanding
Excellent
Outstanding
FAIL
Predict the output?
class jump_statments
{
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y)
{
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
} } }
1 3 5 7
2 4 6 8
1 3 5 7 9
1 2 3 4 5 6 7 8 9
