Java Programming OOPs
Questions 161 to 170
java server page is an extension of
(a) html (b) xml (c) xhtml (d) sgml
(e) java servlet.
|
|||||||
Consider the following program while noting the missing
variable declaration indicated by ?????? :
in
the class Tree.
class
Tree {
??????
Tree()
{
treeNo++;
System.out.println("Tree
"+ treeNo + " is created!"); }
}
public
class Variable{
public
static void main(String[] args) {
Tree
t1 = new Tree();
Tree
t2 = new Tree();
Tree
t3 = new Tree(); }
}
The
output of the above program should turn out to be as shown below:
Tree
1 is created!
Tree
2 is created!
Tree
3 is created!
Select from among the following the correct variable declaration required in the class Tree to get
the above output on the console:
(a)
int static treeNo = 0; (b)
int treeNo; (c) static int
treeNo;
(d)
static final int treeNo; (e)
int treeNo = 0;
|
|||||||
Consider the following additional driver program:
public
class Main {
public
static void main(String[] args) {
ClassB
b = new ClassB(1);
ClassC
c = new ClassC(2);
}
}
Which of the following would the output be?
|
|||||||
What is the result of the expression 75.22 + “5.2”?
(a) The double value in 80.42 (b) The string in “80.42”.
(c) The string is “75.225.2” (d) The string is “75.222.5”
(e) The long value is 80.
|
|||||||
Consider the following Java program to answer this
Question:
public
class Main {
private
String s;
Main()
{
this.print("Main()
constructor");
}
static
void print(String s) {
System.out.println(s);
this.s
= s;
}
String
getLastPrint() {
return
s;
}
public
static void main(String[] args) {
Main
m = new Main();
m.print("Hello");
Main.print("Hello
World");
String
last = m.getLastPrint();
What would be the output of the above program if it is
executed?
|
|||||||
Consider the following program written in Java to answer
this Question:
01.class
StringEx{
02.public
static void main(String args[]) {
03.String
s1="University of ICFAI”;
04.String
s2="hello";
05.String
s3="HELLO”;
06.System.out.println(s1.substring(10,13));
07.System.out.println(s2.equalsIgnoreCase(s3));
08.}
09.}
What would be the output of the statement indicated in
line number 06 when the program is executed?
(a)
University of ICFAI (b)
error (c)
of
(d)
Colombo (e)
ity.
|
|||||||
Consider the following program written in Java to answer
this Question:
01.class
StringEx{
02.public
static void main(String args[]) {
03.String
s1="University of ICFAI”;
04.String
s2="hello";
05.String
s3="HELLO”;
06.System.out.println(s1.substring(10,13));
07.System.out.println(s2.equalsIgnoreCase(s3));
08.}
09.}
What would be the output of the statement indicated in
line number 07 when the program is executed?
(a)
HELLO (b) error (c) of (d) false (e) true.
|
|||||||
Consider the following program written in Java:
class
User {
private
String userName;
private
int userType;
public
void setUserName(String s) {
this.userName
= s;
}
public
void setUserType(int t) {
this.userType
= t;
}
public
String getUserName() {
return
userName;
}
public
int getUserType() {
return
userType;
}
}
public
class Main {
public
static void main(String[] args) {
User
u = new User();
System.out.println(u.getUserName());
System.out.println(u.getUserType());
}
}
Which of the following is the output?
|
|||||||
Consider the following segment of a Java program:
int
x=1;
switch(x)
{
case
0:System.out.println(x);break;
case
1:System.out.println(x);break;
case
2:System.out.println(x);
default:
System.out.println(x);
}
What will the output be when the above segment is executed
as a program?
|
|||||||
Consider the following program written in Java:
class
Iteration{
public
static void main(String args[])
{
for(int i=0;i<5;i++)
{
System.out.println(i);
if(i%2==0)
System.out.println('\t');
}
}
}
When the program is executed what would the outcome be?
|
Answers
Answer : (e)
Reason : Remaining
all are mark up languages
|
|
Answer : (c)
Reason : the
remaining all would not give the required output
|
|
Answer : (a)
Reason : After
execution the output of the given question is of choice A other are
contradictory
|
|
Answer : (c)
Reason : When one
oper and is floating value and the other operated is string, the ‘+’ operator
acts like concantenation. So the result would be a string of 75.225.2”.
|
|
Answer : (e)
Reason : Not a valid code
|
|
Answer : (c)
Reason : The extracted
string of 10, 13 is OF
|
|
Answer : (e)
Reason : True because
equalsignorecase ignores case and returns true
|
|
Answer : (b)
Reason : Remaining
all are contradictory.
|
|
Answer : (b)
Reason : x is taken
as 1 and case 1 is executed and comes out of the switch.
|
|
Answer : (e)
Reason : In other
cases the values are less compared to required output.
|
thank you.
ReplyDeletejava tutorial
java tutorial
why 163 is not e) too ?
ReplyDelete