You are on page 1of 4

1-What isThe Concept of dynamic binding? allows a variable to take different types on the content at a particular time.

2- Sort the Modifiers by the their privates? Public: The class, data, or method is visible to any class in any package. Default: the class, variable, or data can be accessed by any class in the same package protected :The data or methods can be accessed only by the declaring class or sub class. private :The data or methods can be accessed only by the declaring class. 3-What is the Three ways to call a method:? - Using a method name by itself to call another method of the same class - Using a variable that represents an object, followed by a dot (.) and the method name to call a method of that object - Using the class name and a dot (.) to call a static method of a class. 4-what an Argument promotion? converting an arguments value, if possible, to the type that the method expects to receive in its corresponding parameter The promotion have to be performed without losing data Each value is promoted to the highest type in the expression 5-what mean by shadowing ? Any block may contain variable declarations If a local variable or parameter in a method has the same name as a field of the class, the field is hidden until the block terminates execution . 6- what is Garbage and who Collect them? after the assignment statement c1 = c2, c1 points to the same object referenced by c2. The object previously referenced by c1 is no longer referenced. This object is known as garbage. Garbage is automatically collected by JVM. 7-what is an Immutable Objects and Classes? 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. If you delete the set method in the Circle class in the preceding example, the class would be immutable because radius is private and cannot be changed without a set method. 8-What Class is Immutable? For a class to be immutable, it must mark all data fields private and provide no mutator methods and no accessor methods that would return a reference to a mutable data field object 9- what is mutator methods and no accessor methods? mutator methods :method that change any field on the class set methods accessor methods: method that get any field on the class

10- Are superclasss Constructor Inherited? No. They are not inherited. They are invoked explicitly or implicitly. Explicitly using the super keyword If the keyword super is not explicitly used, the superclass's no-arg constructor is automatically invoked.. 11- An instance method can be overridden only if it is accessible. Thus a private method cannot be overridden, because it is not accessible outside its own class. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated. Like an instance method, a static method can be inherited. However, a static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden 12- Method Matching vs. Binding Matching a method signature and binding a method implementation are two issues. The compiler finds a matching method according to parameter type, number of parameters, and order of the parameters at compilation time. A method may be implemented in several subclasses. The Java Virtual Machine dynamically binds the implementation of the method at runtime 13- What is The final Modifier? The final class cannot be extended: The final variable is a constant final static double PI = 3.14159; The final method cannot be overridden by its subclasses. 14- What is The instanceof Operator? Use the instanceof operator to test whether an object is an instance of a class: Object myObject = new Circle(); ... // Some lines of code /** Perform casting if myObject is an instance of Circle */ if (myObject instanceof Circle) { System.out.println("The circle diameter is " + ((Circle)myObject).getDiameter()); ... } 15- What is a Casting ? 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. In the preceding section, the statement m(new Student()); Explicit casting must be used when casting an object from a superclass to a subclass. This type of casting may not always succeed. Apple x = (Apple)fruit; Orange x = (Orange)fruit; To help understand casting, you may also

get methods

16-What is an interface? Why is an interface useful? An interface is a classlike construct that contains only constants and abstract methods. In many ways, an interface is similar to an abstract class, but the intent of an interface is to specify behavior for objects. For example, you can specify that the objects are comparable, edible, cloneable using appropriate interfaces. 17- What is the Relationships between Classes? Association Aggregation Composition Inheritance Association represents a general binary relationship that describes An association is usually represented as a data field in the class. Association may exist between objects of the same class. For example, a person may have a supervisor. Aggregation is a special form of association, which represents an ownership relationship between two classes. Aggregation models the has-a relationship. If an object is exclusively owned by an aggregated object, the relationship between the object and its aggregated object is referred to as composition. An aggregation relationship is usually represented as a data field in the aggregated class. Inheritance models the is-an-extension-of relationship between two classes 18- Using Inheritance or Aggregation? In general, the difference between inheritance and aggregation is the difference between the isan-extension-of relationship and the has-a relationship. For example, an apple is fruit; thus, you would use inheritance to model the relationship between the classes Apple and Fruit. A person has a name; thus, you would use aggregation to model the relationship between the classes Person and Name 19- Procedural vs. Event-Driven Programming? Procedural programming is executed in procedural order. In event-driven programming, code is executed upon activation of events. An event can be defined as a type of signal to the program that something has happened. The event is generated by external user actions such as mouse movements, mouse clicks, and keystrokes, or by the operating system, such as a timer. 20-What is Inner class? A class is a member of another class. Advantages: In some applications, you can use

consider the analogy of fruit, apple, and orange with the Fruit class as the superclass for Apple and Orange. An apple is a fruit, so you can always safely assign an instance of Apple to a variable for Fruit. However, a fruit is not necessarily an apple, so you have to use explicit casting to assign an instance of Fruit to a variable of Apple 21- Applications vs. Applets? Similarities Since JFrame and JApplet both are subclasses of the Container class, all the user interface components, layout managers, and eventhandling features are the same for both classes. Differences Applications are invoked from the static main method by the Java interpreter, and applets are run by the Web browser. The Web browser creates an instance of the applet using the applets no-arg constructor and controls and executes the applet through the init, start, stop, and destroy methods. Applets have security restrictions Web browser creates graphical environment for applets, GUI applications are placed in a frame 22- What is Security Restrictions on Applets? read or write from or to the computer's file system run programs on the user's computer establish a connection between the user's computer and any other computer except for the server where the applet is stored. Java doesn't support pointers (a programmer can't access the memory directly) Memory management is done automatically by the JVM (not the programmer's job C++) 23-descus the methods of applet? The init() Method Invoked when the applet is first loaded and again if the applet is reloaded. Common functions implemented in this method include creating threads, loading images, setting up user-interface components, and getting parameters from the <applet> tag in the HTML page. The start() Method Invoked after the init() method is executed; also called whenever the applet becomes active again after a period of inactivity (for example, when the user returns to the page containing the applet after surfing other Web pages). Functionality might include restarting threads (for example, to resume an animation) or simply telling the applet to run again.

an inner class to make programs simple. An inner class can reference the data and methods defined in the outer class in which it nests, so you do not need to pass the reference of the outer class to the constructor of the inner class.

24-What is aFive-Layer Model? Object oriented analysis and design is based on a five-layer model: Class/object layer notes the classes and objects Structure layer captures various structures of classes and objects, such as one-to-many relationships and inheritance Attribute layer details the attributes of classes Service layer notes messages and object behaviors Subject layer divides the design into implementation units or team assignments 25- Five General Types of Objects? Tangible things Roles Incidents Interactions Specifications details 26-Criteria to Determine Need for a New Class of Objects There is a need to remember the object There is a need for certain behaviors of the object An object has multiple attributes A class has more than one object instantiation Unless it is a base class Attributes have a meaningful value for each object in a class Services behave the same for every object in a class Objects implement requirements that are derived from the problem setting Objects do not duplicate attributes and services that could be derived from other objects in the system 27-What is Instance Connections? Instance connections are references between objects such as associations or relationships indicated by a single line between objects using the same cardinality notation as Whole-Part structures 28- Defines the fallowing ? A class: defines all the characteristics common to a type of object A class is used to instantiate an object, A class, or group of related objects

The stop() Method The opposite of the start() method, which is called when the user moves back to the page containing the applet; the stop() method is invoked when the user moves off the page. When the user leaves the page, any threads the applet has startedbut not completed will continue to run. The destroy() Method Invoked when the browser exits normally to inform the applet that it is no longer needed and that it should release any resources it has allocated. Usually, you will not need to override this method unless you need to release specific resources, such as threads that the applet created. 29-Descus Encapsulation? Encapsulation changes the manner in which data is updated by programs because data can only be changed via the services that encapsulate the data Uses modules to: Hide implementation details Allow programmers to view software as a black box Publish an interface that lists the services provided by the black box Encapsulation allows the implementation to be changed without affecting the interface Encapsulation keeps related content together; it minimizes traffic between different parts of the work; and it separates certain specified requirements from other parts of the specification which may use those requirements. 30-Descus Inheritance ? The two types of classes are involved in any inheritance relationship are the base class and the derived class Multiple inheritance means there will be multiple occurrences of the base type of class in the inheritance relationship Allows a class to be based on another class The new class inherits attributes, behaviours and implementation New attributes and behaviours may be added OR, attributes and behaviours may be overridden The Is-a test is the inherited class of the same type tells us whether to use inheritance If you can not inherit use composition simply create an instance of the class inside the new class Inheritance is the mechanism which allows a class A to inherit properties od class B.

Attributes are characteristics Behaviour are actions objects perform when passed a message (a method is called) An object :is an instance or occurrence of a class Method: Services (or methods or procedures) must be analyzed. Activities are Object state analysis, showing changes of state Service specification: creating, storing, retrieving, connecting, accessing, and deleting objects Message specification, consisting of control and data flow CRC Cards Class, responsibilities, and collaborators (CRC) cards are used to represent the responsibilities of classes and the interaction between the classes Packages Packages are groups of things They can be physical subsystem

Objects of class A thus have access to attributes and methods of class B without the need to redefine them. 31-Descus Polymorphism? only occurs where there is inheritance This means the state of having many forms A single name can express different behaviours Overloading : single name can express different behaviours same function name and let the computer use the correct one based on the type of the arguments you give. That's exactly what overloading is all about. Overraiding : objects are a subclass of other objects and inherit all of their attributes.. But what if the public method of the superclass of a certain object is not exactly as you would like it to be ? Well, you can redefine the method for that objet and still keep the same name. Managing complexity Procedural abstraction The process is started by expressing a top-most statement (or function) that represents the task to accomplish. Data abstraction the programmer needs to concentrate on the data in terms of operations that apply to those data. This is the Object Oriented paradigm.

You might also like