100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

PRO192 Review Questions and Answers

Rating
-
Sold
-
Pages
108
Grade
A
Uploaded on
09-08-2024
Written in
2024/2025

PRO192 Review Questions and Answers

Institution
Course











Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Course

Document information

Uploaded on
August 9, 2024
Number of pages
108
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

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
$12.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
smartchoices Chamberlain College Of Nursing
Follow You need to be logged in order to follow users or courses
Sold
32
Member since
5 year
Number of followers
5
Documents
4466
Last sold
23 hours ago

4.8

9 reviews

5
7
4
2
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions