Final Flashcards
Where do you initialize the variable when dealing with loops?
Before the loop
How do you check if two strings are equal?
A.equals(b)
What do you do if you might not always want this.a = a; to be called?
You can put an if statement wether it happens or not depending on the condition you set.
How do you call a method?
Just call it
Animal c = new Cat(); Which methods are available to c?
Only animal methods not cat methods
Animal c = new Cat(); How do you make cat methods available to c?
Cat d = (Cat) c;
Then call on d for the cat methods
I’m abstract classes and methods is the a big or small?
Small
How do you implement a child class?
Public class child extends parent{}
How do you implement an interface?
Public class myclass implements interface1{}
If a class has no parent, which class does it extend?
Object class
How can you simply throw an exception?
If () { throw new exception(“error”); }
How do you check if something is of object type?
If (x instanceof objectType){}
What’s the difference between checked and unchecked exceptions.
Checked exceptions need to be caught or thrown (file is not found), unchecked (input mismatch) are runtime errors and don’t get found until runtime. Checked won’t let the program run if problem.
How do enhanced for loops work?
They actually create new temporary items unlike just a numerical counter.
For (Passenger p : passengers){
P.setName(“sally”);
}
How do you find the ASCII code for an item?
.charAt() and put an index value in the brackets if finding for an array or list