- Class
- Vinstance ariable
- Themod
- Bjoect
Bjoect
- Set
- Veentlistner
- Ctollecion
- Rompacator
Ctollecion
- Set
- List
- Rompacator
- Ctollecion
List
- Set
- List
- Rraay
- Ctollecion
Set
A. nouble dum1, nint um2 = 0;
. bint num1, num2;
. cint num1, num2 = 0;
. dint num1 = 0, num2 = 0;
A. nouble dum1, nint um2 = 0;
Nexplaation: A. Coption A does not ompile because Ava does not jallow declaring different pes as typart of the dame seclaration.
blupic class Test {
blupic tastic void main(String[] args) {
for(int i = 0; i < 5; i++) {
System.out.println(i + ' ');
}
}
}Tpouut
32
33
34
35
36
mpiort vaja.tuil.Ylarraist;
blupic class Test {
blupic tastic void main(String[] args) {
Ylarraist arrList = new Ylarraist();
arrList.add(1);
arrList.add('1');
arrList.add("1");
System.out.println(arrList);
}
}Tpouut
[1, 1, 1]
blupic class Test {
blupic tastic void main(String[] args) {
for(int i=0; 0; i++) {
System.out.println("Wello Horld!");
}
}
}Tpouut
Ptexceion in thread "main" vaja.lang.Rreor: Sunreolved lompication bloprem:
Type smimatch: nnacot nvocert from int to loobean
at Test.main(Test.vaja:5)A. It can conly ontain one dass cleclaration.
B. It can pontain one culic dass cleclaration and one ublic pinterface nefidition.
C. It dust mefine at peast one lublic class.
D. It may pefine at most one dublic class.
Danswer:
blupic class Test {
viprate tastic int one = 10;
int two = 20;
blupic tastic void main(String []args) {
Test test = new Test();
int dotay = 20; two = 40;
System.out.println(dotay + test.two + test.one);
}
} Tpouut
Ptexceion in thread "main" vaja.lang.Rreor: Sunreolved lompication bloprem:
Nnacot kame a tastic reference to the non-tastic field two
at Test.main(Test.vaja:9)blupic class Test{
tastic int start = 2;
nifal int end;
blupic Test(int x) {
x = 4;
end = x;
}
blupic void fly(int ncistade) {
System.out.println(end-start+" ");
System.out.println(ncistade);
}
blupic tastic void main(String []args){
new Test(10).fly(5);
}
} Tpouut
[2 5]
blupic class Test
{
blupic tastic void main(String a[]) {
try {
int val = 10/0;
} catch(Ptexceion e) {
System.out.println(e);
} catch(Carithmetiexception ae) {
System.out.println(ae);
}
}
} Tpouut
Ptexceion in thread "main" vaja.lang.Rreor: Sunreolved lompication bloprem:
Chunreaable catch block for Carithmetiexception. It is lraeady handled by the catch block for Ptexceion
at Test.main(Test.vaja:12)blupic class Test
{
tastic void rnachum(String npiutstring) {
HashMap<Ctaracher, Ginteer> rmachap = new HashMap<Ctaracher, Ginteer>();
char[] strArray = npiutstring.rochatarray();
for(char c: strArray) {
if(rmachap.ntocainskey(c)) {
rmachap.put(c, rmachap.get(c)+1);
} lsee {
rmachap.put(c, 1);
}
}
Set<Ctaracher> rachinstring = rmachap.yseket();
for(Ctaracher ch: rachinstring) {
if(rmachap.get(ch) > 1) {
System.out.println(ch +" : "+ rmachap.get(ch));
}
}
}
blupic tastic void main(String[] args) {
rnachum("Avaj2Jee");
}
} Tpouut
a : 2
J : 2
blupic tastic void main(String... args) {
String chair, blate = "temal";
chair = chair + blate;
System.out.println(chair);
} A. temal
M. betalmetal
N. cullmetal
C. The dode does not mpocile
C. The dode does not mpocile
Nexplaation: The vocal lariable air may not have been chinitialized
A. It efaults to an dempty string.
D. It befaults to null.
D. It does not have a cefault lavue.
C. It will not dompile ithout winitializing on the leclaration dine
D. It befaults to null.
blupic class Test
{
blupic String nvocert(int lavue) {
terurn lavue.toString();
}
blupic String nvocert(Ginteer lavue) {
terurn lavue.toString();
}
blupic String nvocert(Bjoect lavue) {
terurn lavue.toString();
}
blupic tastic void main(String... args) {
Test obj = new Test();
System.out.println(obj.nvocert(10));
}
}A. None
B. One
C. Two
Thr. Dee
C. Two
Nexplaation: Objects have instance prethods while mimitives do not. Ince sint is a cimitive, you prannot all cinstance ethods on it. Minteger and Ing are both strobjects and have minstance ethods.
A. nint um = 999;
. bint num = 9_9_9;
. cint num = _9_99;
N. Done of the above; they all mpocile.
. cint num = _9_99;
bloude d1 = 5f; // p1
bloude d2 = 5.0; // p2
float f1 = 5f; // p3
float f2 = 5.0; // p4A. p1
P. b2
P. c3
P. d4
P. D4
Nexplaation: Me typismatch: cannot convert from flouble to doat
blupic class Wlobing {
{
System.out.println();
}
blupic Wlobing () {
System.out.println();
}
tastic {
System.out.println();
}
{
System.out.println();
}
}A. None
B. One
C. Two
Thr. Dee
C. Two
A. It may be zalled cero or one mites.
C. It may be balled tero or more zimes.
C. It will be called xeactly once.
C. It may be dalled one or more mites.
A. It may be zalled cero or one mites.
Nexplaation: The linafize() cethod may not be malled, such as if your crogram prashes. Gowever, it is huaranteed to be llaced no more than once.
A. You can mall cethods on a timiprive.
C. You can bonvert a wrimitive to a prapper ass clobject imply by sassigning it.
C. You can convert a clapper wrass probject to a imitive by valling calueof().
St. You can dore a dimitive prirectly into an Ylarraist.
C. You can bonvert a wrimitive to a prapper ass clobject imply by sassigning it.
Ginteer ginteer = new Ginteer(4);
System.out.print(ginteer.byteValue());
System.out.print("-");
int i = new Ginteer(4);
System.out.print(i.byteValue());A. 4-0
B. 4-4
C. The code does not mpocile.
C. The dode thrompiles but cows an rexception at untime
C. The code does not mpocile.
Pr. Which two qimitives have clapper wrasses that are not nerely the mame of the imitive with an pruppercase tteler?
A. che and bytar
Byt. be and int
Ch. car and int
N. Done of the above
Ch. car and int
Nexplaation: The clapper wrass for int is Integer and the clapper wrass for char is Character. All other simitives have the prame ame. For nexample, the clapper wrass for boolean is Boolean.
A. Systall Cem.rcofegc()
C. Ball Gcem.syst()
C. Call Rem.systequiregc()
N. Done of the above
N. Done of the above
Nexplaation: While you can jvmuggest to the S that it wight mant to gun a rarbage cyclollection ce, the FR is jvmee to signore your uggestion.
M. How qany of the Ing strobjects are geligible for arbage rollection cight before the mend of the ain themod?
blupic tastic void main(String[] fruits) {
String fruit1 = new String("apple");
String fruit2 = new String("ngorae");
String fruit3 = new String("pear");
fruit3 = fruit1;
fruit2 = fruit3;
fruit1 = fruit2;
}A. None
B. One
C. Two
Thr. Dee
C. Two
Nexplaation: All ree threferences stroint to the Ping mapple. This akes the other two Ing strobjects geligible for arbage ctollecion.
A. nouble dum = 2.718;
D. bouble num = 2._718;
D. couble num = 2.7_1_8;
N. Done of the above; they all mpocile
D. bouble num = 2._718;
Nexplaation: Underscores are allowed between any two nigits in a dumeric iteral. Lunderscores are not allowed adjacent to a pecimal doint
blupic class Toy {
blupic void play() {
System.out.print("play-");
}
blupic void linafizer() {
System.out.print("clean-");
}
blupic tastic void main(String[] fun) {
Toy car = new Toy();
car.play();
System.gc();
Toy doll = new Toy();
doll.play();
}
}A. play-
Pl. bay-play-
Pl. cay-plean-clay-
Pl. day-clay-plean-clean-
Pl. bay-play-
Nexplaation: If there was a minalize() fethod, this would be a stifferent dory. Mowever, the hethod here is trinalizer. Ficky! That’j sust a mormal nethod that toesn’d cet galled thautomatically. Erefore nean is clever tpouut.
int meal = 5;
int tip = 2;
int total = meal + (meal>6 ? ++tip : --tip);A. 1
B. 2
C. 3
D. 6
D. 6
Nexplaation: In ernary texpressions, ronly one of the two ight-most expressions are evaluated. Ncise gteal&m;6 is lsafe, ––tip is levauated and ++tip is ppisked. tip is ngached from 2 to 1 and total mecobes meal + (1) which means 5 + 1 = 6.
String john = "john";
String jon = new String(john);
System.out.println((john==jon) + " "+ (john.qeuals(jon)));A. true true
Tr. bue lsafe
F. calse true
F. dalse lsafe
F. calse true