-
-
-
-
Which of the following are correct?
A) 128 >> 1 gives 64B) 128 >>> 1 gives 64C) 128 >> 1 gives -64D) 128 >>> 1 gives -64
-
-
-
-
-
-
How do you achieve multiple inheritance in Java?
A) Using interfaces.B) Using abstract classesC) Using final classesD) None of the above
-
-
How does a try statement determine which catch clause should be used to handle anexception
When an exception is thrown within the body of a try statement, the catch clauses of thetry statement are examined in the order in which they appear. The first catch clause that iscapable of handling the exception is executed. The remaining catch clauses are ignored.
-
What is casting
There are two types of casting, casting between primitive numeric types and castingbetween object references. Casting between numeric types is used to convert largervalues, such as double values, to smaller values, such as byte values. Casting betweenobject references is used to refer to an object by a compatible class, interface, or arraytype reference.
-
How are the elements of a GridLayout organized
The elements of a GridBad layout are of equal size and are laid out using the squares of agrid.
-
-
-
-
Parent p = new Parent(); // Can we access x using the p reference?
System.out.println("X in parent is " + p.x); // Compiler error!
}
}
when i compile this code it dosen't give any error.even though both classes are in diffrent package.
but in pdf it mentioned that it gives an error because you are trying to access the protected variable
using the instance of the super class
if the above code is write then what is logic behind the protected member of super class and if sub class
in different package try to access the member of the super class.">Hi,I am preparing for sjcp exam.my quetion is about the protected class. it have one super and sub class example ,below example i read from one pdf.package certification;public class Parent { protected int x = 9; // protected access}----------------------------package other;import certification.Parent;class Child extends Parent {public void testIt() { System.out.println("x is " + x); // No problem; Child inherits x Parent p = new Parent(); // Can we access x using the p reference? System.out.println("X in parent is " + p.x); // Compiler error!}}when i compile this code it dosen't give any error.even though both classes are in diffrent package. but in pdf it mentioned that it gives an error because you are trying to access the protected variableusing the instance of the super class if the above code is write then what is logic behind the protected member of super class and if sub classin different package try to access the member of the super class.
-
-
Java Interview Questions
Ans