Go:
1 2 R4R --->Java --->> SCJP1.5 Chapter06 --> Sun Java Certification
Page 1
Question:Benefits of Encapsulation
Post Your View
AnswersTwo benefit are there for the Encapsulation :
> flexibility
> maintainability.
These benefits are not become atomatically , we have to do smthing for the enable those things. We should create a classes and code in a way that supports flexibility and
maintainability.
public clas More --- >>
By:UMANG Date:03.03.09
Question:Constructor Basics
Post Your View
Answersevery class must be a constructor including abstract class.A constructor looks like this:
class Foo {
Foo() { } // The constructor for the Foo class
}
constructors are used to initialize instance variable state, as follows:
class Foo {
int size;
String name;
Foo(String name, int size) {
thi More --- >>
By:UMANG Date:04.03.09
Question:Constructor Chaining
Post Your View
AnswersConstructors are invoked at runtime when we say new on some class type as follows :
Horse h = new Horse();
But what really happens when we say new Horse() :
> Horse constructor is invoked.
> Animal constructor is invoked (Animal is the superclass of Horse).
> Object constructor i More --- >>
By:UMANG Date:04.03.09
Question:Determine if a Default Constructor Will Be Created
Post Your View
AnswersHorse class with two constructors :
class Horse {
Horse() { }
Horse(String name) { }
}
Will the compiler put in a default constructor for the class above? No!
class Horse {
Horse(String name) { }
}
Now will the compiler insert a default constructor
class Hors More --- >>
By:UMANG Date:04.03.09
Question:Give the list of Illegal Override Code
Post Your View
AnswersIllegal Override Code | Problem with the Code
-------------------------------------------------
private void eat() { } |Access modifier is more
restrictive.
-------------------------------------------------
public void eat() |Declares a checked
thro More --- >>
By:UMANG Date:04.03.09
Question:give the list of Method Invocation Code
Post Your View
AnswersMethod Invocation Code | Result
----------------------------------------------------
Animal a = new Animal(); |Generic Animal Eating
a.eat(); Generically
----------------------------------------------------
Horse h = new Horse(); |Horse eating hay
h.eat();
More --- >>
By:UMANG Date:04.03.09
Question:Give the list of Overloaded Method
Post Your View
Answers Overloaded Method| Overridden method
----------------------------------------------------
argument list |Must change |must not
change
-----------------------------------------------
return type |Can change |must not
More --- >>
By:UMANG Date:04.03.09
Question:HAS-A Relationship
Post Your View
AnswersHAS-A relationships bassically dependent on the usage, rather than inheritance. We can also say
class A HAS-A B if code in class A has a reference to an instance of class B. For example,
We can say the following :
> A Horse IS-A Animal. A Horse HAS-A Halter. and the code looks like this :
publi More --- >>
By:UMANG Date:03.03.09
Question:Invoking a Superclass Version of an Overridden Method
Post Your View
AnswersWe will want to take advantage of some of the code in the superclass version of a method, yet still override it to provide some additional specific behavior.“Run the superclass version of the method, then come back down here and finish with my subclass additional method code.”It’s easy to do in code More --- >>
By:UMANG Date:03.03.09
Question:Invoking Overloaded Methods
Post Your View
AnswersWhen the method is invoked more than one method of the same name might exist for the object type we’re invoking a method on.Deciding which of the matching methods to invoke is based on the arguments. If we invoke the method with a String argument, the overloaded version that takes
a String is call More --- >>
By:UMANG Date:04.03.09
Question:IS-A Relationships
Post Your View
AnswersIn Object Oriented the concept of IS-A is based on inheritance. IS-A is a way of saying, “this
thing is a type of that thing.”
Our express the IS-A relationship in Java through the keyword extends:
public class Car {
// Cool Car code goes here
}
public class Subaru extends Car {
// More --- >>
By:UMANG Date:03.03.09
Question:Legal Overloads
Post Your View
AnswersWhen we want to overload that code is shown :
public void changeSize(int size, String name, float pattern) { }
The following methods are legal overloads of the changeSize() method :
public void changeSize(int size, String name) { }
public int changeSize(int size, float pattern) More --- >>
By:UMANG Date:04.03.09
Go:
1 2
Contact Us
|