Sie sind auf Seite 1von 4

Nume, Prenume __________________________ Grupa I1445

LUCRARE DE LABORATOR. Răspundeți la întrebări.


1. Ce va fi afisat?
public class HelloWorld { A. true, true
public static void main(String[] args) { B. true, false
String hello = "Hello"; C. false, true
String world = "World!";
String helloWorld = hello + " " + world;
D. false, false
String hw = "HelloWorld!"; E. The code will not compile
boolean b1 = hw == helloWorld;
boolean b2 = hw == "Hello World!" ;
System.out.println(b1 + ", " +b2); } }
2. Ce va fi afisat?
public class FeedingSchedule { raspuns
public static void main (String [] args)
{
int x = 5, j = 0;
OUTER: for(int i = 0; i<3; )
INNER: do {
i++; x++;
if (x >10) break INNER;
x += 4;
j++;
} while (j<=2);
System.out.println(x); } }
3. Ce va fi afisat?
class PU { raspuns
public static void main(String[] args) {
String s ="anaconda" ;
if(s.charAt(0) == s.charAt(s.length()-1))
System.out.println(" True ");
else System.out.println(" False "); } }
4. Ce va fi afisat?
public class IS { raspuns
public static void main(String[] args) {
String s1 = "CAROLINA";
String s2 = "";
int i;
int L1 = s1.length();
for (i=L1-1; i>=0; i--)
s2 =s2+s1.charAt(i);
System.out.println("sirului \t" +s1+ " \neste: \t\t" +s2);
} }
5. Ce va fi afisat?
class Hexy { raspuns
public static void main (String[] args) {
Integer i = 32;
String s = (i<40) ? "life" : (i>50) ? "universe" : "everything";
System.out.println(s);} }
6. Ce va fi afisat?
public class q1 {
enum Univeristy {
USM, CEITI, ASEM, UTM, ULIM, USMF;
}
public static void main(String[] args) {
Univeristy[] unis = Univeristy.values() ;
System.out.println(unis[2]); } }
7. Fie clasele Pet, Snake,Dog, PatrolDog, Cat, Fish
class Pet {
String name; int age; boolean hungry;
void voice() {
}
void food() { hungry = false; } }
class Snake extends Pet { double length; void voice() { System.out.println("Ss-ss-ss"); } }
class Dog extends Pet { void voice() { System.out.println("Bau-bau"); }}
class PatrolDog extends Dog {void voice() { System.out.println("R-r-r-r"); }}
class Cat extends Pet { void voice() { System.out.println("miau-miau"); }}
class Fish extends Pet {
}
public class Main {
public static void main(String[] args) {
Pet zorka = new Pet(); zorka.food();
Fish nemo = new Fish(); nemo.voice(); }
}
ce va fi afisat?
public class RunPet {
public static void main(String[] args) {
Pet zorka = new Pet(); zorka.food();
Dog d=new Dog(); d.voice();
Cat c=new Cat(); c.voice();
Fish nemo = new Fish(); nemo.voice();
if (!c.hungry)
System.out.println("flamind"); }}
8. Fie doua interfete cu metode folosite pentru transportarea pasagerilor si transportarea greutatilor. De
creat clasa Picap pentru transportarea ambelor tipuri de incarcatura marfa si pasageri.
interface PassangersAuto { void transportPassangers(); }
interface CargoAuto { void transportCargo(); }
class Truck implements CargoAuto {
final static int a = 1;
public void transportCargo() {
System.out.println("Transportez marfa"); } }
class Sedan implements PassangersAuto {
public void transportPassangers() {
System.out.println("Transportez pasageri"); } }
rulare
public class RunInterfete {
public static void main(String[] args){
Truck tr=new Truck();
tr.transportCargo();
Sedan sd=new Sedan();
sd.transportPassangers();
} }
Nume, Prenume __________________________ Grupa I1445
LUCRARE DE LABORATOR. Răspundeți la întrebări.
1. Ce va fi afisat?
public class HelloWorld { A. true, false
public static void main(String[] args) { B. . false, true
String hello = "Hello"; C false, false
String world = "World!";
String helloWorld = hello + " " + world;
D. true, true
String hw = "HelloWorld!"; E. The code will not compile
boolean b1 = hw == helloWorld;
boolean b2 = hw == "Hello World!" ;
System.out.println(b1 + ", " +b2);
} }
2. Ce va fi afisat?
public class FeedingSchedule { raspuns
public static void main (String [] args)
{ int x = 7, j = 0;
OUTER: for(int i = 0; i<3; )
INNER: do {
i++; x++;
if (x >12) break INNER;
x += 4; j++;
} while (j<=2);
System.out.println(x); } }
3. Ce va fi afisat?
class PU { raspuns
public static void main(String[] args) {
String s ="fericit" ;
if(s.charAt(0) == s.charAt(s.length()-1))
System.out.println(" True ");
else System.out.println(" False "); } }
4. Ce va fi afisat?
public class IS { raspuns
public static void main(String[] args) {
String s1 = "MAIN";
String s2 = "";
int i;
int L1 = s1.length();
for (i=L1-1; i>=0; i--)
s2 =s2+s1.charAt(i);
System.out.println("sirului \t" +s1+ " \neste: \t\t" +s2);
} }
5. Ce va fi afisat?
class Hexy { raspuns
public static void main (String[] args) {
Integer i = 42;
String s = (i<40) ? "life" : (i>50) ? "universe" : "everything";
System.out.println(s);} }
6. Ce va fi afisat?
public class q1 { raspuns
enum Univeristy {
USM, CEITI, ASEM, UTM, ULIM, USMF, ASM;
}
public static void main(String[] args) {
Univeristy[] unis = Univeristy.values() ;
System.out.println(unis[3]); } }
7. Fie clasele Pet, Snake,Dog, PatrolDog, Cat, Fish
class Pet {
String name; int age; boolean hungry;
void voice() {
}
void food() { hungry = false; }
}
class Snake extends Pet { double length;
void voice() { System.out.println("Ss-ss-ss"); } }
class Dog extends Pet {
void voice() { System.out.println("Bau-bau"); } }
class PatrolDog extends Dog {
void voice() { System.out.println("R-r-r-r"); } }
class Cat extends Pet {
void voice() { System.out.println("miau-miau"); } }
class Fish extends Pet {
void voice() { System.out.println("acvariu");} }
public class Mainn {
public static void main(String[] args) {
Pet zorka = new Pet(); zorka.food();
Fish nemo = new Fish(); nemo.voice();
} }
public class RunPet { // _____________
public static void main(String[] args) { // _______________
Pet zorka = new Pet(); zorka.food(); // _______________
PatrolDog d=new PatrolDog(); d.voice();
Cat c=new Cat(); c.voice();
// _____________
Fish nemo = new Fish(); nemo.voice(); // _______________
if (!c.hungry) // _____________
System.out.println("galagie"); }
// _______________
}
8. Fie doua interfete cu metode folosite pentru transportarea pasagerilor si transportarea greutatilor. De
creat clasa Picap pentru transportarea ambelor tipuri de incarcatura marfa si pasageri.
interface PassangersAuto { void transportPassangers(); }
interface CargoAuto { void transportCargo(); }
class Truck implements CargoAuto {
final static int a = 1;
public void transportCargo() {
System.out.println("Transportez marfa"); } }
class Sedan implements PassangersAuto {
public void transportPassangers() {
System.out.println("Transportez pasageri"); } }
rulare
public class RunInterfete { Ce va vi afisat?
public static void main(String[] args){ // __________
Truck tr=new Truck(); // ____________
tr.transportCargo();
/* adauga codul pentru Picap */ } }

Das könnte Ihnen auch gefallen