Java Programming Questions and Answers Set 28

Java Programming OOPs

Questions 271 to 280



271.
Select from among the following what Java can do?
(a)
Object oriented applications can be developed
(b)
Networking applications can be developed
(c)
Database applications can be developed
(d)
Either  (a) or (b) above
(e)
Either (a) or (b) or (c) above.
272.
In addition to JDK there are a number of Java commercial development tools available for Java programmers. Select from among the following such Java commercial development tool available.
(a)
Borland JBuilder
(b)
Visual Basic.net
(c)
Java Server Pages
(d)
My sql server
(e)
Java Script.
273.
Which is identified as the first ever Object Oriented Programming Language?
(a)
C++
(b)
C
(c)
Java
(d)
Simula 67
(e)
Small talk.
274.
How comments that can be used in Automatic Class Documentation by javadoc tool are represented?
(a)
Started with **/ and Ended with */
(b)
Started with /* and ended with */
(c)
Started with /** and Ended with */
(d)
Started with – and ended with –
(e)
Started with /** and ended with /*.
275.
Which one of the following is legal valid variable name among the following?
Suppose we create the following classes Account and OverdraftAccount to represent bank accounts. An Overdraft Account is a subtype of a general Account.
/** Account represents a mutable bank account. **/
class Account {
double balance;
/** @effects constructs a new Account with
* balance = initialBalance */
Account(double initialBalance) {
this.balance = initialBalance;
}
/** Returns a textual description of the type of this account.
* @return the String "Account" */
String getAccountType() {
return "Account";
}
/** @effects prints to standard output the type of this account
* followed by the balance. */
void printBalance() {
System.out.println(this.getAccountType() + ": $" + balance);
}
}
/** OverdraftAccount represents a mutable bank account with a credit limit.*/
class OverdraftAccount extends Account {
double creditLimit;
/** @effects constructs a new OverdraftAccount with
* balance = initialBalance,
* creditLimit = initialCreditLimit */
OverdraftAccount(double initialBalance, double initialCreditLimit) {
super(initialBalance);
this.creditLimit = initialCreditLimit;
}
/** Returns a textual description of the type of this account.
* @return the String "OverdraftAccount" */
String getAccountType() {
return "OverdraftAccount";
}
}
(a)
1 More
(b)
# Two
(c)
@ Two
(d)
Temp_val
(e)
1234 abc.
276.
The method getAccountType() is invoked in the code for printBalance().
What is the compile-time type of the receiver of this method invocation?
(a)
Object
(b)
Account
(c)
OverdraftAccount
(d)
The answer varies depending on how printBalance() is invoked
(e)
AccountType.
277.
Suppose we now wish to print the balance information for an account with the following code:
Account myAccount = new OverdraftAccount(5, 10);
myAccount.printBalance();
Which of the following statement is true?
(a)
The printed output is the string “Account”
(b)
The printed output is the string “OverdraftAccount”
(c)
The printed output is the string “Account: $5”
(d)
The printed output is the string “OverdraftAccount: $5”
(e)
There will be a compilation error because OverdraftAccount, the run-time type of myAccount, does not define the printBalance() method.
278.
Given the code below:
class A {
public void print() { System.out.println("hi"); }
}
class B extends A {
public void print() { System.out.println("bye"); }
}
What does each of the following code samples do:
A a = new B();
a.print();
(a)
Prints nothing
(b)
Prints “hi”
(c)
Prints “bye”
(d)
The code does not compile, the compiler returns a type error
(e)
The code throws a runtime exception.
279.
Given the code below:
class A {
 public void print() { System.out.println("hi"); }
}
class B extends A {
  public void print() { System.out.println("bye"); }
}
B b = new A();
b.print();
(a)
Prints nothing
(b)
Prints “hi”
(c)
Prints “bye”
(d)
The code does not compile, the compiler returns a type error
(e)
The code throws a runtime exception.
280.
What is the size of the Short integer type in terms of bits?
(a)
8
(b)
16
(c)
32
(d)
64
(e)
128.


Answers


271.
Answer : (e)
Reason:  With Java  Object oriented applications , Networking applications, database applications, can be developed.
272.
Answer : (a)
Reason:  Borland Jbuilder is the right choice as the other are for different purposes.
273.
Answer : (d)
Reason:  Simula67 is the first ever object oriented programming language.
274.
Answer : (c)
Reason:  Remaining are for single line and multiline comments
275.
Answer : (d)
Reason:  variable names should  only Start with a Letter, Underscore (_) , or Dollar Sign ($).After the first letter Name can include any letter or Number but cannot include Symbols such as %, @, *  and so on.
276.
Answer : (b)
Reason:  T he receiver of the method invocation is implicitly "this", which, in the context of the Account class in which the printBalance() resides, has a compile-type of Account. Note that an object has only one compile-time type; thus, circling both Object and Account is incorrect, even though Account is a subtype of Object.
277.
Answer : (d)
Reason:  OverdraftAccont.getAccountType() is called from printBalance() as myAccount has a runtime type of OverdraftAccount.
278.
Answer : (c)
Reason:  T he print() method of the run-time type, B, is called.
279.
Answer : (d)
Reason:  The compiler will not allow you to set an object reference to an instance whose runtime type is a Java supertype of the variable's compile time type.
280.
Answer : (b)
Reason:  Short integer in 16 bits or 2 bytes



<< Prev   1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22  

 23   24   25   26   27   28   29   30  Next >>


1 comment :