Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

PRO192 Review Questions and Answers

Beoordeling
-
Verkocht
-
Pagina's
108
Cijfer
A
Geüpload op
09-08-2024
Geschreven in
2024/2025

PRO192 Review Questions and Answers

Instelling
Vak

Voorbeeld van de inhoud

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

Geschreven voor

Vak

Documentinformatie

Geüpload op
9 augustus 2024
Aantal pagina's
108
Geschreven in
2024/2025
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

$12.99
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF


Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
smartchoices Chamberlain College Of Nursing
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
36
Lid sinds
5 jaar
Aantal volgers
5
Documenten
4499
Laatst verkocht
1 maand geleden

4.8

9 beoordelingen

5
7
4
2
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen