Save
Upgrade to remove ads
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

OOP fa4

QuestionAnswer
Here is a situation: Birthday happy; happy = new AdultBirthday( "Joe", 39); happy.greeting(); Which greeting() method is run: the one defined for Birthday or the one defined for AdultBirthday? The one defined for AdultBirthday because that is the type of the object referred to by happy.
Which among the following can't be used for polymorphism? Group of answer choices Predefined operator overloading Member functions overloading Static member functions Constructor overloading Static member functions
Casting superclass references to subclass references is known as downcasting. True
Which among the following is not true for polymorphism? Increases overhead of function definition always
What must be true if a child of an abstract parent class does not override all of the parent's abstract methods? The child class itself must be declared to be abstract.
Which of the following is FALSE about abstract classes in Java A class can inherit from multiple abstract classes.
Which is the following statement(s) is/are correct? X: A class can be marked as abstract with out containing any abstract method. Y: If a class has even one abstract method, then the class has to be an abstract class. Both are correct
Which is true about interfaces in java 1) interface can have type of member public, static, final fields default static methods w/ bodies 2) instance of interface can be created 3) class can implement multiple interfaces. 4) Many classes can impleme 1, 3 and 4
Which of the following statement(s) is/are correct? X: An abstract class can have one or more abstract methods. Y: An abstract class can have only abstract. Non abstract (or concrete) methods are not allowed. X only
What is an abstract method? An abstract method is one without a body that is declared with the reserved word abstract.
Which among the following is not a method of Throwable class? Group of answer choices public void printStackTrace() public String getMessage() public Char toString() public Throwable getCause() public Char toString()
Why do we need to handle exceptions? Group of answer choices To encourage exception prone program To avoid syntax errors To save memory To prevent abnormal termination of program To prevent abnormal termination of program
What are two exception classes in hierarchy of java exceptions class? Group of answer choices Runtime exceptions only Other exceptions Runtime exceptions and other exceptions Compile time exceptions only Runtime exceptions and other exceptions
public class Test extends Exception{ private String mess; public Test(String message) this.mess = mess; public static void main(String[] args) int a = 5, b = 3; try if( a % b > 0 ) throw new test Compilation error
What happens during execution if an negative value is used for an array index? An IndexOutOfBoundsException is thrown.
Only way to enable assertion for your program is by using command line arguments. False
What happen when you compile with command “java Test -10” public class Test{ public static void main(String[] args){ int temp = Integer.parseInt(args[0]); assert temp > 0 : temp = 0; System.out.println(temp); The code will not compile
which line is an example of an inappropriate use of assertions? assert z > 0; /* Line 11 */ assert z > 2: foo(z); /* Line 12 */ assert z > 4; /* Line 14 */ assert z > 4: z++; /* Line 22 */ Line 22
Which of the following statements is true? It is sometimes good practice to throw an AssertionError explicitly.
What will happen when you compile w/ assertion public class Test{ public static void main(String[] args){ displayAge(20); } private static void displayAge(int age){ assert age >= 21 : getAgeMessage(); System.out.println(age); } private static St The code will compile but will throw AssertionError when executed
Fill in the blanks so that the following draws a Frame containing "Hello". import java.awt.*; class helloFrame ___________ Frame{ public void ___________( Graphics g ){ g.___________("Hello", 10, 50 );}} extends, paint, drawString
An abstract class declares a common interface for the various members of a class hierarchy. The abstract class contains methods that will be declared in the subclasses. All classes in the hierarchy can use this same set of methods through polymorphism. True
Unfortunately, polymorphic programs make it difficult to add new capabilities to a system. False
What do you call the languages that support classes but not polymorphism? Group of answer choices If classes are supported, polymorphism will always be supported Object-based language Procedure Oriented language Class based language Object-based language
Rodent rod; Rat rat = new Rat(); Mouse mos = new Mouse(); PocketMouse pkt = new PocketMouse(); Which one of the following will cause a compiler error? pkt = rat;
Which of the following classes fail to compile? class X { } abstract class Y { } class Z { abstract void method(); } Z
Abstraction principle includes___________ Group of answer choices Use abstraction whenever possible to avoid duplication Use abstraction to avoid longer codes Use abstraction whenever possible to achieve OOP Use abstraction at its minimum Use abstraction whenever possible to avoid duplication
Can an abstract method be defined in a non-abstract class? No--if a class defines an abstract method the class itself must be abstract.
Higher the level of abstraction, higher are the details. False
Why do we use finally block? Group of answer choices To execute a code when exception is not occurred To execute a code whenever required To execute a code with each and every run of program To execute the block if exception occurred To execute a code whenever required
An exception may arise when _______________ Group of answer choices Input is valid Input is fixed Input is some constant value of program Input given is invalid Input given is invalid
Say that a method catches an IOException in a catch{} block. Is it possible for that block to do some processing and then throw the same exception to the caller? Yes---as long as the method also has a throws clause for that exception.
There can be a try block without catch block but vice versa is not possible. Group of answer choices False True True
It is not required for the caller method to catch or re-throw the checked exception. False
assert false; /* Line 5 */ assert false; /* Line 6 */ while(true) { assert false; /* Line 12 */ } assert false; /* Line 14 */ Line 14, kase infinite loop yung line 12
What will be the output of the program (when you run with the -ea option) ? public class Test { public static void main(String[] args) { int x = 0; assert (x > 0) : "assertion failed"; /* Line 6 */ System.out.println("finished"); An AssertionError is thrown.
What causes compilation to fail? assert false; /* Line 5 */ assert false; /* Line 6 */ while(true) { assert false; /* Line 12 */ } assert false; /* Line 14 */ Choices: Line12 Line13 Line 10 Line 14 Line 14
public class Test{ public static void main(String[] args){ int[] marks = {40, 38, 52}; boolean[] pass = {false, false, false}; for(int i = 0 ; i < marks.length; i++){ try{ assert marks[i] >= 40 : pass[i] = true; }catch(AssertionError ae){ pass[i] The code will compile and print false,false,false,
Created by: palpakan56
 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards