100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
PRO192 Review Questions and Answers $12.49   Add to cart

Exam (elaborations)

PRO192 Review Questions and Answers

 6 views  0 purchase
  • Course
  • Institution

PRO192 Review Questions and Answers

Preview 4 out of 108  pages

  • August 9, 2024
  • 108
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
avatar-seller
PRO192 Review Questions and Answers

class Bird {
String place, color; int weight;
Bird(){weight=1;}
Bird(String place, String color){
this.place = place;
this.color = color;
this.weight = 2;
}
Bird(String place, String color, int weight){
this.place = place;
this.color = color;
this.weight = weight;
}

@Override
public String toString() {
return ("("+place+", "+color+", "+weight+")");
}
}

public class Main {
public static void main(String[] args) {
Bird x,y,z;
x = new Bird();
y = new Bird("Hola", "blue");
z = new Bird("Hola", "blue", 5);
System.out.println(x);
System.out.println(y);
System.out.println(z);
}
} *** Output:
(null, null, 1)
(Hola, blue, 2)
(Hola, blue, 5)

=> weight = 1 và this.weight = 2 đều trỏ đến thuộc tính weight (của class Bird) nên đều
in được như thường.

public class Vase {
String color;
int price;

,Vase(){
price = 5;
}

Vase(String color, int price) {
this.color = color;
this.price = price;
}

@Override
public String toString() {
return (color+","+price); //To change body of generated methods, choose Tools |
Templates.
}
}

class SpecVase extends Vase{
int type;
SpecVase(){type = 5;}

SpecVase(String color, int price, int type) {
super(color, price);
this.type = type;
}

void display(){
String s = "("+super.toString()+","+type+")";
System.out.println(s);
}

public static void main(String[] args) {
SpecVase v = new SpecVase();
v.display();
}
} *** Output: (null, 5, 5)
Tương tự câu trên

A programmer need to create a logging method that can accept an arbitrary number of
argument. For example, it may be called in these ways:
loglt("log message 1");
loglt("log message 2","log message 3");
loglt("log message 4","log message 5","log message 6");
which declaration satisfies this requirement?
A. public void loglt(String... msgs)
B. public void loglt(String[] msgs)
C. public void loglt(String * msgs)

,D. public void loglt(String msgs1, String msgs2, String msgs3) *** A
muốn số lượng đối số trong hàm tùy ý => dùng "..."

what is the output when the following program is run?
class A {public int x;}
public class Main
{
static void fun(A t) {t.x += 2;}
public static void main(String args[])
{A t = new A();
t.x = 99;
System.out.print(t.x + " ");
t.x++; // tăng 1
System.out.print(t.x + " ");
fun(t); // tăng 2
System.out.print(t.x);
}
}
A. 98 99 101
B. 99 99 101
C. 99 100 100
D. 99 100 101
E. 99 100 102 *** E

given the following class definition
public class Upton{
public static void main(String args[]){
}
public void amethod(int i){}
//here
}
Which of the following would be illegal to place after the comment //here?
A. private void anothermethod(){}
B. public int amethod(int z){}
C. public int amethod(int i,int j){return 99;}
D. protected void amethod(long l){} *** B
Không thể trùng signature: kiểu dữ liệu, tên hàm, các tham số trong hàm (overloading).
ACD hợp lệ do: A khác tên, C khác kiểu dữ liệu, D khác tham số.

What will happen when you attempt to compile and run the following code?
import java.io.*;
class Base{
public static void amethod()throws FileNotFoundException{}
}
public class ExcepDemo extends Base{
public static void main(String argv[]){

, ExcepDemo e = new ExcepDemo();
}

public static void amethod(){}
protected ExcepDemo(){
try{
DataInputStream din = new DataInputStream(System.in);
System.out.println("Pausing");
din.readChar();
System.out.println("Continuing");
this.amethod();
}catch(IOException ioe) {}
}
}
1) Compile time error caused by protected constructor2) Compile time error caused by
amethod not declaring Exception3) Runtime error caused by amethod not declaring
Exception4) Compile and run with output of "Pausing" and "Continuing" after a key is hit
*** 4

What will happen when you attempt to compile and run this code?
import java.io.*;
class Base{
public static void amethod()throws FileNotFoundException{}
}
public class ExcepDemo extends Base{
public static void main(String argv[]){
ExcepDemo e = new ExcepDemo();
}
public static void amethod(int i)throws IOException{}
private boolean ExcepDemo(){
try{
DataInputStream din = new DataInputStream(System.in);
System.out.println("Pausing");
din.readChar();
System.out.println("Continuing");
this.amethod();
return true;
}catch(IOException ioe) {}
finally{
System.out.println("finally");
}
return false;
}
}
1) Compilation and run with no output.2) Compilation and run with output of "Pausing",
"Continuing" and "finally"3) Runtime error caused by amethod declaring Exception not

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller smartchoices. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $12.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

81849 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$12.49
  • (0)
  Add to cart