| Terms |
Definitions |
|
Do rules of overriding apply for private methodsi.e. private void jump() public void jump()
|
No it does not
|
|
Final class : 1.can’t be subclassed, 2.no class can extend a final class.which is true?
|
both statements are
|
|
Float f = 23.23568 fails, why?
|
Float f = 23.23568F (needs to be attached) because a FP literalis deinfed a s a double (64 bits), not with 32 bits
|
|
Source File Structure:package com.geeks;import java.util.* //wild card package importimport com.wicketlysmart.Foo; //Explicit class import.WIll these compile
|
YES
|
|
Why these not compile?import java.util.ArrayList.* import java.util;
|
import java.util.ArrayList.* => won’t compile because it is a class not package.import java.util; //won’t compile since util is not a class.
|
|
These classes are default, can this compile and why?i.e. package cert; package exam.stuff ___class Bev{ } import cert.Bev; ____class Tea extend Bev { //can’
|
No because thtey are both in DIFFERENT packages. We can make one of the classes public to make it compile
|
|
static void b(); //compile?
|
illegal, defines instance methods
|
|
• int[ ] [ ] books new int [3] [];• int [ ] numbers = new int[6];• int aNumber = 7;• books[0] = aNumber // Compile?
|
No , expect an int array instead of int
|
|
HOw many public class per source code.1. 02. 13. 2
|
1
|
|
• Just as with array elements, instance variables are always initialized with a default value.T or F
|
T
|
|
Delcare an array Two ways: before or after namea) int [ ] key;b) int key [ ] ;which is recommended (a) or (b)?
|
a
|
|
abstract static doStuff();Is this legal?
|
NO
|
|
For objects, can be modified, but reference variable (bit pattern can’t be changed). final Date d = new Date();d.setYear(2001) //compilesd = new Date (); //can’t compile why not?
|
because we’re changing the bit pattern. (ref variable)
|
|
Local variables only have___ access public int x = 7protected int x = 7final int x = 7static int x = 7
|
final int x = 7
|
|
int[] splats;int [] dats = new int[4];char[] letters = new char[5];splats = letters //legal?
|
NO, letters refer to a char array
|
|
final instance variables need to be intilized by the time the _______ method appears.
|
constructor
|
|
synchronized final method?compiles
|
YES
|
|
For instance variableswhat are the 3 legal types?
|
final, transietn, volatire
|
|
Do local variables get default values?
|
NO
|
|
Protected Keyword (used for inheritance) [Packaged kids]:used to define a member, any subclass of the class declaring the member can access it regardless if they are different packages. The subclass can only see the protected member through inheritance
|
YES because of inheritance
|
|
Is this legal?Dog puppy = new Dog(“Frodo”);Dogs[] myDogs = {puppy, new Dog (“Clover”), new Dog(“Aiko”)};
|
Yes
|
|
A flat is a ___ bit floating point number
|
32
|
|
Default Members (Package restrictions)- can be accessed only if the class accessing the member belongs to the ____ package.a. differentb. SAME
|
SAME
|
|
Declare, construct, and assign this in one line.TEST SCORES array of ints size of 4.
|
int [] testScores = new int[4];
|
|
int [ ] [ ] scores = { {5,2,4,7}, {9,2}, {3,4} };scores [0] // holds this array {5,2,4,7}scores [2] //holds this array {3,4}scores[2][1] //Accesses which value?
|
4 [{3,4}]
|
|
Char literals can also be represented as an integer, as long as it’s less than 1. 655362. 655373. 65538
|
1. 65536
|
|
int[] splats;int [] dats = new int[4];char[] letters = new char[5];splats = dats; // legal?
|
Ok, dats refer to an int array
|
|
abstract synchronized, strictfp, native void thisMethod(); ?lega?
|
NO explains implemenation detils...
|
|
Synchronized – only applies to ______, can be accessed only one thread at a time.classsesmethods
|
methods
|
|
abstract final Method? legal?
|
No, contradicts
|
|
Protected Keyword (used for inheritance) [Packaged kids]:used to define a member, any subclass of the class declaring the member can access it regardless if they are different packages. The subclass can only see the protected member through inheritance
|
Compiler error, trying to access it through parent reference!
|
|
Multidimensional Arrays - are these legal?1. int [ ] [ ] ratings = new int [3] [ ];2. scores [0] = new int [4];3. scores [1] = new int [6];4. scores [2] = new int [1];
|
yes
|
|
default value for char is a.‘\u0000’b. 0
|
a.‘\u0000’
|
|
Native used only for ____implemented in a platform independent way,never combined with abstract.classes or methods?
|
methods
|
|
Is this legal?char c = 70000;
|
No, out of range, less than 65536, to make legal use cast char c = (char) 70000
|
|
class Honda extends Car { implement methods here }Which is the parent abstract class?
|
Car
|
|
• The first command-line argument is the first element in the main String array parameter.%java TestMain Hello//First arg is ____
|
Hello
|
|
Is this legal?final stricttfp class
|
Yes because strictfp applies to classes or methods
|
|
What does this printi.e. class Frog{ static int frogCount = 0; public Frog() { frogCount +=1; }public static void main (String [] args){ new Frog(); new Frog(); System.out.println(frogCo
|
frogCount = 2!
|
|
• When an array of primitives is instantiated, all elements get their default valuesT or F
|
T
|
|
Instance of using const, for a constant which key word do we use?a.staticb.finalc.private
|
b.final
|
|
a double is a 64 bit flopating pointis it signed or unsigned?
|
SIGNED
|
|
For instance variables, what is illegal? (4)
|
abstract, syyncrhoized, strictfp, natvie
|
|
//Local objects and arraysDate d ;if (d == null){System.out.println(“date is null”);}Why will this crash?
|
//Will crash because you have to explicitly set d to null. A null references Is not the same as an uninitalized reference!
|
|
public abstract class A{ abstract void foo();}class B extends A{void foo(int I){ //will this line compile?}}
|
won’t compile this is overloaded!
|
|
Is this legal?char c = -29
|
No , possible of loss of precision, need a cast, char is unsigned.
|
|
scores = new int[3] {4,7,2} //legal?
|
scores = new int[3] {4,7,2} //legal? NO – do not put size.
|
|
An array has a ____ relationship. class Car{}, class Honda extends Car{}i.e. Car [ ] my Cars = { new Honda() };a. IS-Ab. HAS-A
|
IS-A
|
|
• If no arguments are passed to main, the length of the main String array parameter will be ____
|
zero
|
|
When an array of objects is instantiated, objects within the array are instantiated automatically.T or f?
|
F
|
|
A char is a unicode char.. how many bits.8,16,32,64?
|
16 bit unsigned.
|
|
Is this legal?int[5] scores;
|
No, never legal to include the size of array in declaration
|
|
package cert;public class Parent { int x = 9 ;//default}package cert;class Child extends Parent{ public void testIt(){ System.out.println(x); // compiles? }}
|
yes because its in the same package
|
|
Is this legal?final abstract class
|
NO, a class can never be FINAL AND ABSTRACT. contradiction abstract(has to be extended), final can’t
|
|
Both short and byte are SIGNED integers.How many bit does a bye have?
|
8
|
|
package cert;public class Parent { int x = 9 ;//default}package different;class Child extends Parent{ public void testIt(){ System.out.println(x); // cam we ise this “x”. }}
|
NO
|
|
Abstract Methods: declared but not implemented, required to be ________a. extendedb. declared
|
extended
|
|
Why is this illegal?int x = 1; if (x) { }
|
Because x is not "true" or "false"
|
|
Abstract class MKUST BE1. Instantiated2. Extended (sublcasses)3. BOTH
|
2. Absturact classes can ONLY be extended NEVER instantiated
|
|
Is this legal?
|
No because arrays must always be given a size at the time they are constructed.
|
|
Both short and byte are SIGNED integers.How many bit does a short have?
|
16
|
|
a long is a _____ bit ______ integer
|
64 signed
|
|
Is this legal abstract strictfp class Blah?
|
Yes because strictfp applies to classes or methods.
|
|
This deinfes what kind of character?char c = ‘\”’; 1. double quote2. single quote
|
1. double quote
|
|
• Local/automatic/method variables are always given a default value. If you attempt to use one before initializing it, it will compile but Instance Variables are T or F
|
False
|
|
an int is a a 32 bit SIGNED or UNSIGNED ?
|
SIGNED
|
|
Why is this illegal ?public int break(int b) { }public int switch(int b) {}
|
break and switch are reserved key words
|
|
• int[ ] [ ] books new int [3] [];• int [ ] numbers = new int[6];• int aNumber = 7;• books[0] = numbers //
|
Compile? Yes, numbers is an int array.
|
|
public/private/default/protected synchronized method ?legal?
|
YES
|
|
From broadest to the narrowest which is the correct order?double float, long, int, byte, shortdouble, float, int, long, byte,shortdouble, long, flat, short, int , bytedouble, float, long,int, short, byte
|
double, float, long,int, short, byte
|
|
public final class ? Is this legal?
|
Yes because of inheritance
|
|
Strictfp => used for both Classes and what kind of methods:
|
non-abstract methods
|
|
Legal?int [] scores;scores = new int[] {4,7,2};
|
YES/used for just in time array
|
|
Why is this illegal ?public int break(int b) { }public int switch(int b) {}
|
break and switch are reserved key words
|
|
How do you intilize array of dotsin one line as a list.
|
int[] dots = {3,6,x,8};
|
|
Will this compile?abstract class Car{ private double price; public abstract void goFast();}
|
YES
|
|
strictfp can modify which of the followingclassmethodvariable
|
class AND method ONLY
|
|
Is this legal?char b = 982;
|
Yes because its an int literal
|
|
synchronized final class?compiles?
|
NO because synchronized only applies to methods
|
|
Which keyword is not implmeneted in java because its harmful?a. abstractb. gotoc. transient
|
b. goto
|