• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/77

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

77 Cards in this Set

  • Front
  • Back

What is the difference between a class and an object?

A class is a blueprint for an object of variables and behaviors. An object is a real set of variables and behaviors stored in the RAM.

What is the purpose of a constructor? How is a constructor different from other methods? What happens when a constructor is called

A constructor is used to initialize an object. It's different because it needs the same name as the class and does not have a return type. Memory is allocated in the RAM for the object when called.

MyTestmt;MyTestmt = new MyTest ();How is line 1 different from like 2? What does line 1 and line 2 achieve?

Line 1 calls the object, line 2 creates an object , thus saving a place in the RAM for it. MyTestmt in line 1 = null,Line 2 initializes and contains the address of the object.

How is a variable in a method or function different from a global variable? Consider the initial values. What happens when a global and local variable have the same name

A variable in a method or function is local, it's only available in that method. A global variable is available to the entire class. If they have the same name, the global variable is used. If it's in a method, the local variable will be used unless you use the this.variable syntax to call the global variable. Instance/global variables have a default value, local do not.

How is a variable storing a primitive data type different from a variable holding a reference for an object of a class?

Primitive stores the actual value of the data, reference stores a reference of the memory location.

How is storing an array different from storing a primitive data type?

Arrays are an object, are stored in a location. The address is stored as a reference.Primitive stores the actual value.

What is the difference between passing variable by value and passing variable values by reference?

Passing by value means a copy of the value is being passed.Pass by reference is an address of the variable being passed.

Why are arrays and objects always passed by reference?

Arrays and objects are passed by reference because it's easier and the size is unknown.Primitive data types have a known size.

Explain the difference between shallow and deep copies of an object?

A shallow copy is only a copy of the reference, any changes made will be reflected in the original object.A deep copy of object is the same state and values stored in different locations, you can safely change a value without it reflecting upon the original object.

What is an instance variable?

A variable declared inside a class, but outside a method.

What is a static variable?

A class only has one of a static variable, it's value is reserved, even out of scope. It is self contained and belongs to the class, not the object.Can be called without creating an object. Static methods can only use other static variables!

What is a static method and how is a static method different from other methods?

A method that belongs to a class rather than an instance of a class. It is accessible to every instance of a class, but methods defined in an instance are only able tobe accessed by that member.

What do we mean by scope?

Defines section of code in which variable is visible. A set of curly braces defines a scope {}.

Scope of instance variable?

In the class bit outside method.

Scope of static variable?

The entire class, almost like a global variable.

Scope of local variable?

Within it's method or function.

public int intx (int x){


return x++;


}

Yes, it is self contained and can be static.

public int getX(){


return x;


}

No, it needs to retrieve x so it's not self contained and cannot be static.

public int setX (int value){


x = value;


}

No, setting an instance variable.

public double sqRoot (double y){


logic


let's say sqr=sqRoot;


}


return sqr;


}

Yes, self contained, can be static.

public int [ ] sort(int [ ] data){


logic for sorting


return sorted


}

Yes, self contained, can be static.

public double getArea (){


return length *width;


}

No, instance variables need to be retrieved, cannot be static.

public double salary (Employee emp){return emp.hours * emp.hourlyPay;


}

Yes, self contained, playing with object variables, can be made static.

Limited in scope

Constructors are a special kind of method that are invoked to

construct objects

A constructor with no parameters is referred to as a

no-arg constructor;

a default constructor, is provided automatically only if

no constructors are explicitly defined in the class.;

To reference an object, ---

assign the object to a reference variable.

To declare a reference variable, use the syntax:

ClassName objectRefVar;



Referencing the object’s data:

objectRefVar.data

Invoking the object’s method:

objectRefVar.methodName(arguments)


e.g., myCircle.getArea();

If a data field of a reference type does not reference any object, the data field holds

a special literal value, null. ;

Instance variables belong to a

specific instance.

Instance methods are invoked by

an instance of the class.;

Static variables are shared by

all the instances of the class.

Static methods are not tied to

a specific object.

Static constants are

final variables shared by all the instances of the class.;

public
The class, data, or method is visible to any class in any package.;

private

The data or methods can be accessed only by the declaring class.;

The get and set methods are used to

read and modify private properties;

The private modifier restricts access to ----, the default modifier restricts access to ----, and the public modifier enables ----. ;

within a class, within a package, unrestricted access

If the contents of an object cannot be changed once the object is created, the object is called an ----

immutable object and its class is called an immutable class.;

For a class to be immutable, it must mark all --- and provide ----that would return a reference to a mutable data field object.;

data fields private, no mutator methods and no accessor methods.

Class abstraction means to ----

separate class implementation from the use of the class.;

A String object is immutable; its contents ----.

cannot be changed

A regular expression (abbreviated regex) is a string that ----. Regular expression is a powerful tool for ----. You can use regular expressions for matching, replacing, and splitting strings.;

describes a pattern for matching a set of strings, string manipulations.

A constructor is used to ----.Unlike properties and methods, a superclass's constructors are ----. They can only be invoked from the ----, using the keyword super. If the keyword super is not explicitly used, the superclass's----.;

construct an instance of a class.


-not inherited in the subclass, subclasses' constructors, no-arg constructor is automatically invoked.

You must use the keyword super to call the superclass constructor. Invoking a superclass constructor’s name in a ----. Java requires that the statement that uses the keyword super appear ----.;

subclass causes a syntax error, first in the constructor.

Constructing an instance of a class invokes all the superclasses’ ----. This is known as ----.;

constructors along the inheritance chain, constructor chaining.

A subclass inherits from a superclass. You can also:

Add new properties


Add new methods


Override the methods of the superclass;

A subclass inherits methods from ----. Sometimes it is necessary for the subclass to ----. This is referred to as ----.;

a superclass, modify the implementation of a method defined in the superclass, method overriding.

An instance method can be overridden only if ---. Thus a ----method cannot be overridden, because it is not----. If a method defined in a subclass is private in its superclass, the two methods are ----.;

it is accessible, private, accessible outside its own class, completely unrelated.

Like an instance method, a ---- method can be inherited. However, a static method cannot be ----. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is ----.;

static, overridden, hidden.

Polymorphism means that a variable of a ----.;

supertype can refer to a subtype object.

A class defines a ----. A type defined by a subclass is called a ----, and a type defined by its superclass is called a ----. Therefore, you can say that Circle is a subtype of GeometricObject and GeometricObject is a supertype for Circle.;

type, subtype, supertype.

You have already used the casting operator to convert variables of one primitive type to another. Casting can also be used to ----.;

convert an object of one class type to another within an inheritance hierarchy.

Explicit casting must be used when ----. This type of casting may not always succeed.;

casting an object from a superclass to a subclass.

Use the ---- operator to test whether an object is an instance of a class:;

instanceof.

Why is this code not compiling correctly??



Public static void main (String args []){


C c = new C ();


}}



Class A {


Public A (int x){


Systen.out.println ("Hello from A's overloaded constructor.");


}}


Class B extends A { }


Class C extends B { }

I dunno lol

If a method overloads another method, these two methods must have the same exactsignature

False

A method can be overloaded in the same class

True

A method can be overridden in the same class

False

It is a compilation error if overloaded methods differ only in return type

True, arguments must differ

A method in a subclass can overload a method in the superclass

True

A subclass is usually extended to contain more functions and more detailed informationthan its superclass

True

"class A extends B" means A is a subclass of B

True

Class B is a subclass of A so it is ok to use B b=new A ()

True

A sub-class reference type can be assigned to a super class object without casting

False

Method behavior must strictly bind with its name at the compile time always

False

All classes have a toString() method

True

All Classes have a common superclass.

True

If a method is overridden in a subclass, there is no way we can call its superclass version

False

Static binding means matching method signatures.

True

Dynamic binding happens at run time.

False

Bb

X