100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
PRO192 Review Questions and Answers €11,84   In winkelwagen

Tentamen (uitwerkingen)

PRO192 Review Questions and Answers

 6 keer bekeken  0 keer verkocht
  • Vak
  • Instelling

PRO192 Review Questions and Answers

Voorbeeld 4 van de 108  pagina's

  • 9 augustus 2024
  • 108
  • 2024/2025
  • Tentamen (uitwerkingen)
  • Vragen en antwoorden
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

Voordelen van het kopen van samenvattingen bij Stuvia op een rij:

√  	Verzekerd van kwaliteit door reviews

√ Verzekerd van kwaliteit door reviews

Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!

Snel en makkelijk kopen

Snel en makkelijk kopen

Je betaalt supersnel en eenmalig met iDeal, Bancontact of creditcard voor de samenvatting. Zonder lidmaatschap.

Focus op de essentie

Focus op de essentie

Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper smartchoices. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €11,84. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 81849 samenvattingen verkocht

Opgericht in 2010, al 14 jaar dé plek om samenvattingen te kopen

Start met verkopen
€11,84
  • (0)
  Kopen