Programski Jezici 1.Kol

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Akacadjo
A
Akacadjo
Community Contributor
Quizzes Created: 1 | Total Attempts: 372
Questions: 52 | Attempts: 372

SettingsSettingsSettings
Programski Jezici 1.Kol - Quiz

.


Questions and Answers
  • 1. 

    Kako se klasa definise kao apstraktna?

    • A.

      Ne mora se eksplicitno definisati vec se podrazumeva ukoliko postoje metode koje nisu definisane

    • B.

      Dodavanjem kljucne reci abstract ispred imena nedefinisanih metoda, bez dodavanja bilo cega u zaglavlje klase

    • C.

      Ubacivanjem kljucne reci abstract u zaglavlje klase

    • D.

      Ubacivanjem kljucne reci final u zaglavlje klase

    • E.

      Ubacivanjem kljucne reci volatile u zaglavlje klase

    Correct Answer
    C. Ubacivanjem kljucne reci abstract u zaglavlje klase
    Explanation
    An abstract class is defined by adding the keyword "abstract" in the class header. This indicates that the class cannot be instantiated and may contain abstract methods, which are methods without a body. By adding the "abstract" keyword, it is explicitly stating that the class is abstract.

    Rate this question:

  • 2. 

    Sta je izlaz sledeceg programa u Javi: class Roditelj { void prikazi()  {    System.out.println("Roditelj");   } } class Dete extends Roditelj { void prikazi()   {     System.out.println("Dete");   }   public static void main(String args[])  {   Roditelj r = new Dete();   r.prikazi();   } }

    • A.

      Dete

    • B.

      Desice se greska u kompajliranju, posto se u instrukciji Roditelj r = new Dete(); pokusava promenljivoj koja je tipa Roditelj dodeliti objekat koji je drugacijeg tipa

    • C.

      Desice se greska u kompajliranju, posto je metoda prikazi() vec nasledjena u klasi Dete() i nije moguce dodatno je izmeniti u samoj klasi Dete

    • D.

      Roditelj

    Correct Answer
    A. Dete
    Explanation
    The output of the program is "Dete" because the main method creates an object of the Dete class and assigns it to a reference variable of type Roditelj. When the prikazi() method is called on this object, the version of the method defined in the Dete class is executed, which prints "Dete" to the console. This demonstrates polymorphism, where a subclass object can be assigned to a superclass reference variable and the appropriate method is called based on the actual type of the object.

    Rate this question:

  • 3. 

    Ukoliko nam neki objekat vise nije potreban u programu, kako to eksplicitno mozemo ukazati?

    • A.

      Dodelom reference null

    • B.

      Eksplicitnim pozivom procedure Garbage Collection, gde kao parametar prosledjujemo objekat za brisanje

    • C.

      Brisanjem pokazivaca sa delete

    • D.

      Nije moguce u Javi

    Correct Answer
    A. Dodelom reference null
    Explanation
    In Java, when an object is no longer needed in the program, we can explicitly indicate this by assigning the reference to null. This means that the reference no longer points to any object, allowing the Java garbage collector to eventually remove the object from memory. This is a common practice to free up memory and optimize the performance of the program.

    Rate this question:

  • 4. 

    Koje tvrdnje su tacne za interfejse:

    • A.

      Moguce je napisati i implementaciju pojedinih objektnih metoda direktno u interfejsu

    • B.

      Sastoji se od skupa apstraktnih metoda, bez implementacije

    • C.

      Interfejs moze imati konstruktor

    • D.

      Obezbedjuje slicne mogucnosti kao visetruko nasledjivanje

    Correct Answer(s)
    B. Sastoji se od skupa apstraktnih metoda, bez implementacije
    D. Obezbedjuje slicne mogucnosti kao visetruko nasledjivanje
    Explanation
    Interfejsi se sastoje od skupa apstraktnih metoda bez implementacije, što znači da samo deklarišu metode koje treba implementirati u klasama koje ih implementiraju. Ovo omogućava da se definiše zajednički skup metoda koje klase moraju implementirati, ali ne definiše njihovu konkretne implementaciju. Takođe, interfejsi omogućavaju klasama da implementiraju više interfejsa, što pruža slične mogućnosti kao višestruko nasleđivanje.

    Rate this question:

  • 5. 

    Ukoliko zelimo da sprecimo dalje izvodjenje iz nase klase, u njenom zaglavlju se mora staviti kljucna rec:

    • A.

      Final

    • B.

      Static

    • C.

      Const

    • D.

      Abstract

    • E.

      Forbidden

    Correct Answer
    A. Final
    Explanation
    The correct answer is "final". In Java, the "final" keyword is used to prevent further derivation or extension of a class. When a class is declared as "final", it cannot be subclassed or inherited by any other class. This is useful when we want to ensure that the class remains unchanged and cannot be modified or extended by other developers.

    Rate this question:

  • 6. 

    Ukoliko je apstraktna klasa A definisana sa apstraktnom metodom metodaA(), a klasa B nasledjuje klasu A, koje tvrdnje su tacne?

    • A.

      Nije dozvoljeno da klasa B prosiri klasu A, posto metodaA() u klasi A nije dovrsena, pa je i nasledjivanje zabranjeno

    • B.

      Klasa B ne implementira metodaA(), i klasa B je u tom slucaju konkretna klasa koja se moze instancirati

    • C.

      Klasa B implementira metodaA(), i klasa B je u tom slucaju konkretna klasa koja se moze instancirati

    • D.

      Klasa B ne implementira metodaA(), ali u tom slucaju mora i ona biti definisana kao apstraktna i ne moze se instancirati

    Correct Answer(s)
    C. Klasa B implementira metodaA(), i klasa B je u tom slucaju konkretna klasa koja se moze instancirati
    D. Klasa B ne implementira metodaA(), ali u tom slucaju mora i ona biti definisana kao apstraktna i ne moze se instancirati
    Explanation
    If class B implements methodA(), it means that it provides a concrete implementation of the abstract method defined in class A. In this case, class B is a concrete class that can be instantiated. On the other hand, if class B does not implement methodA(), it must also be defined as abstract and cannot be instantiated.

    Rate this question:

  • 7. 

    Ukoliko zelimo da obezbedimo mogucnost sortiranja objekata nase klase (na primer metodom Arrays.sort() ), moramo uraditi sledece stvari:

    • A.

      Klasa mora da implementira interfejs Comparable i definise metodu compareTo()

    • B.

      Klasa mora da implementira interfejs Comparable i definise metodu compare()

    • C.

      Nije potrebni uraditi nista, posto osnovna podrska za sortiranje je vec nasledjena iz klase Object

    • D.

      Klasa mora da prosiri apstraktnu klasu Comparable i redefinise metodu compareTo()

    Correct Answer
    A. Klasa mora da implementira interfejs Comparable i definise metodu compareTo()
    Explanation
    The correct answer is that the class must implement the Comparable interface and define the compareTo() method. This is because the compareTo() method is used by the sorting algorithm to compare objects and determine their order. By implementing the Comparable interface and providing the compareTo() method, we allow the sorting method (e.g. Arrays.sort()) to correctly sort objects of our class based on our specified criteria.

    Rate this question:

  • 8. 

    Koje tvrdnje za definisanje klase su tacne?

    • A.

      Clanovi podaci klase su uvek dostupni spoljasnjme okruzenjju klase

    • B.

      Clanovi podaci klase mogu da budu zasticeni ili javni (izlozeni)

    • C.

      Clanovi podaci klase uvek moraju da se pisu van tela klase

    • D.

      Clanovi podaci klase moraju da budu definisani unutar tela metoda klase kao promenljive

    • E.

      Clanovi podaci klase koji su metode moraju da se definisu unutar tela klase

    • F.

      Clanovi podaci klase mogu da budu i promenljive i metode

    • G.

      Clanovi podaci klase koji su metode moraju da se definisu izva tela klase

    • H.

      Clanovi podaci klase moraju da budu definisani unutar tela klase, a van tela metoda te klase

    Correct Answer(s)
    B. Clanovi podaci klase mogu da budu zasticeni ili javni (izlozeni)
    E. Clanovi podaci klase koji su metode moraju da se definisu unutar tela klase
    F. Clanovi podaci klase mogu da budu i promenljive i metode
    Explanation
    The correct answer states that class data members can be protected or public, class data members that are methods must be defined within the class body, and class data members can be both variables and methods.

    Rate this question:

  • 9. 

    Princip podtipa u Javi obezbedjuje da:

    • A.

      Objekat nekog podtipa (izvedene klase) moze se uvek koristiti tamo gde se ocekuje objekat njegovog nadtipa (bazne klase)

    • B.

      Objekat nekog nadtipa se moze koristiti uvek tamo gde se ocekuje objekat njegovog podtipa (izveden klase)

    • C.

      Promenljiva tipa neke klase moze da sadrzi iskljucivo objekte samo te klase, a ne i izvedenih klasa

    Correct Answer
    A. Objekat nekog podtipa (izvedene klase) moze se uvek koristiti tamo gde se ocekuje objekat njegovog nadtipa (bazne klase)
    Explanation
    This answer correctly states the principle of subtype polymorphism in Java. It means that an object of a derived class (subtype) can always be used where an object of its base class (supertype) is expected. This is a fundamental concept in object-oriented programming, as it allows for code reusability and flexibility by treating objects of different derived classes as objects of their common base class.

    Rate this question:

  • 10. 

    U sledecem kodu: public class MyVlacc { private int value; public void setValue(int i){ / kod  / } } Metod setValue dodeljuje vrednost promenljive i atributu value. Koji od sledecih delova koda se moze napisati u telu metode da bi se definisala ovakva metoda?

    • A.

      Super(i);

    • B.

      Value==i;

    • C.

      Value=i;

    • D.

      This.value=i;

    Correct Answer(s)
    C. Value=i;
    D. This.value=i;
    Explanation
    The correct answer is "value=i;" and "this.value=i;". In order to assign the value of the parameter "i" to the attribute "value", we can use either "value=i;" or "this.value=i;". Both statements achieve the desired result of assigning the value of "i" to the attribute "value".

    Rate this question:

  • 11. 

    Ukoliko u programu imamo klase Vozilo, PutnickoVozilo i TeretnoVozilo, koja je najverovatnija organizacija klasa?

    • A.

      Sve tri klase su na istom nivou, bez dodatnog izvodjenja

    • B.

      Klasa Vozilo je bazna klasa, a PutnickoVozilo i TeretnoVozilo su klase izvedene iz klase Vozilo

    • C.

      Klasa PutnickoVozilo je izvedena iz klase Voizlo, a klasa TeretnoVozilo logicki ne pripada toj familiji klasa

    • D.

      Klasa PutnickoVozilo je izvedena iz klase Vozilo, a klasa TeretnoVozilo je izvedena iz klase PutnickoVozilo

    Correct Answer
    B. Klasa Vozilo je bazna klasa, a PutnickoVozilo i TeretnoVozilo su klase izvedene iz klase Vozilo
    Explanation
    The most likely organization of classes is that the class "Vozilo" is the base class, while "PutnickoVozilo" and "TeretnoVozilo" are derived classes from the class "Vozilo". This means that "PutnickoVozilo" and "TeretnoVozilo" inherit properties and methods from the base class "Vozilo".

    Rate this question:

  • 12. 

    Oznaci sintaksno ispravna zaglavlja klase ( pretpostavlja se da sve nasledjene klase i interfejsi postoje):

    • A.

      Public class MyClassSub extends MyClass1, MyClass2{}

    • B.

      Public class MyClassSub extends MyClass implements MyInterface{}

    • C.

      Public class MyClass{}

    • D.

      Public class MyClassSub extends MyClass{}

    Correct Answer(s)
    B. Public class MyClassSub extends MyClass implements MyInterface{}
    C. Public class MyClass{}
    D. Public class MyClassSub extends MyClass{}
    Explanation
    The correct answer is a combination of three options. The first option "public class MyClassSub extends MyClass implements MyInterface{}" is syntactically correct because it extends the class MyClass and implements the interface MyInterface. The second option "public class MyClass{}" is also correct as it defines the class MyClass. The third option "public class MyClassSub extends MyClass{}" is also valid as it extends the class MyClass. Therefore, the correct answer includes all three options.

    Rate this question:

  • 13. 

    Tekuca instanca klase, odnosno promenljiva klasnog tipa koja u trenutku poziva metode dobija vrednost reference na objekat za koji je metoda pozvana, u Javi se oznacava sa kljucnomreci:

    • A.

      Static

    • B.

      Instance

    • C.

      Super

    • D.

      New

    • E.

      This

    Correct Answer
    E. This
    Explanation
    In Java, the keyword "this" is used to refer to the current instance of a class. It is used to access the members (variables and methods) of the current object. By using "this", we can differentiate between the instance variables and parameters with the same name. It is commonly used in constructors and setter methods to set the values of instance variables.

    Rate this question:

  • 14. 

    Date su definicije klase A i klase B u Javi? public class A public void say() {    System.out.print("Hello from an instance of the class A!"); } public class B extends A { public void say()   {       System.out.print("Hello from an instance of the class B!");    } } Sta ce biti ispisano na standardnom izlazu posle izvrsenja sledeceg koda u main metodi? A a = new B(); a.say();

    • A.

      Hello from an instance of the class A!

    • B.

      Programski kod u klasi B nece moci da se prevede, jer u klasi B ne moze postojati metoda sa istim nazivom i istim parametrima kao u klasi A

    • C.

      Hello from an instance of the class B!

    • D.

      Prevodjenje programskog koda nece biti moguce jer refernca tipa A ne moze ukazivati na objekat tipa B

    Correct Answer
    C. Hello from an instance of the class B!
    Explanation
    The correct answer is "Hello from an instance of the class B!" because the code creates an object of class B and assigns it to a reference of type A. Since class B extends class A and overrides the say() method, when the say() method is called on the object, it will execute the version of the method defined in class B, which prints "Hello from an instance of the class B!"

    Rate this question:

  • 15. 

    Sta ce biti ispisano na standardnom izlazu nakon izvrsenja sledeceg koda? class A {     int i;     public void display()     {       System.out.println(i);      } } class B extends A {      int j;      public B( int i, int j){         this.i=i;         tihs.j=j;      }      public void display()     {         System.out.println(j);      } } class Test {      public static void main(String args[])      {          B obj2 = new B(1,2);          A r = obj2;          r.display();       } }

    • A.

      Greska prilikom kompajliranja, objektu r klase A se dodeljuje objekat klase B

    • B.

      Greska prilikom kompajliranja, klasa A nema definisan konstruktor

    • C.

      1

    • D.

      2

    • E.

      Greska prilikom kompajliranja posto se pristupa atributu i klase A u konstruktoru klase B

    Correct Answer
    D. 2
    Explanation
    The code will result in a compilation error because the class A does not have a defined constructor.

    Rate this question:

  • 16. 

    Konkretna klasa koja implementira dati interfejs A, mora da:

    • A.

      Nije neophodno eksplicitno deklarisati u zaglavlju klase da se implementira interfejs A

    • B.

      eksplicitno deklarise u zaglavlju klase da implementira interfejs A kljucnom reci implements

    • C.

      Eksplicitno deklarise u zaglavlju klase da implementira interfejs A kljucnom reci extends

    • D.

      definise sve metode iz interfejsa A

    • E.

      Definisemo deo metoda iz interfejsa A

    Correct Answer(s)
    B. eksplicitno deklarise u zaglavlju klase da implementira interfejs A kljucnom reci implements
    D. definise sve metode iz interfejsa A
    Explanation
    The correct answer is "eksplicitno deklarise u zaglavlju klase da implementira interfejs A kljucnom reci implements, definise sve metode iz interfejsa A". This is because in order for a specific class to implement a given interface, it must explicitly declare in the class header that it implements interface A using the keyword "implements". Additionally, the class must define all the methods from interface A.

    Rate this question:

  • 17. 

    Posmatra se sledeci kod. Sta ce biti ispisano na standardnom izlazu kao rezultat rada programa? final class Complex {      private final double re;      private final double im; } public String ispisi() {     return "( " +  re  + " +  "+ im + "i)";    } } class Main {    public static void main(String args[])    {         Complex c = new Complex(10, 15);         System.out.println(c);     } }

    • A.

      Desice se greska tokom izvrsavanja programa (runtime error) posto je klasa definisana kao final

    • B.

      Complex@8e2fb5 (8e2fb5 je hashcode objekta c)

    • C.

      (10.0 + 15.0i)

    • D.

      Dobice se greska u kompajliranju

    Correct Answer
    B. Complex@8e2fb5 (8e2fb5 je hashcode objekta c)
    Explanation
    The program will output "Complex@8e2fb5 (8e2fb5 is the hashcode of object c)". This is because when we try to print an object directly, it will call the toString() method of the object. Since the Complex class does not have a toString() method, it will use the default implementation from the Object class, which returns the class name followed by the hashcode of the object.

    Rate this question:

  • 18. 

    Da li je dozvoljeno napisati sledeci kod u Javi: class Sabiranje {   void saberi(int a, int b)    {      System.out.println(a+b);     }    void saberi(int a, int b, int c)//change no of arguments i.e 3    {     System.out.println(a+b+c);    } }

    • A.

      Dozvoljeno je, u pitanju je klasican primer preopterecenja (overload) metoda, posto metode imaju razlicite potpise

    • B.

      Nije dozvoljeno, metode imaju isto ime i nije moguce odrediti koja se poziva

    • C.

      Nije dozvoljeno, moraju se razlikovati i povratni tipovi metoda

    • D.

      Nije dozvoljeno, posto nije naveden modifikator prisutupa, obazvezno je uz metode pisati public, protected ili private

    Correct Answer
    A. Dozvoljeno je, u pitanju je klasican primer preopterecenja (overload) metoda, posto metode imaju razlicite potpise
    Explanation
    The given code is allowed in Java because it demonstrates a classic example of method overloading. The two methods in the class "Sabiranje" have the same name but different parameter lists, which is allowed in method overloading. This means that the methods can be called with different arguments, and the appropriate method will be executed based on the number and types of the arguments. Therefore, the code is valid and demonstrates the concept of method overloading.

    Rate this question:

  • 19. 

    Public class MyClass {   int i;   public MyClass(){/code/}   public MyClass(int i){/code}  //more code... } Kako se moze kreirati objekat ove klase?

    • A.

      MyClass mc = new MyClass(i);

    • B.

      Konstruktor mora da bude definisan kao public void MyClass();

    • C.

      MyClass mc = new MyClass();

    • D.

      MyClass mc = MyClass(i);

    Correct Answer(s)
    A. MyClass mc = new MyClass(i);
    C. MyClass mc = new MyClass();
    Explanation
    The correct answer is MyClass mc = new MyClass(i);. This is because the class MyClass has two constructors - a default constructor with no parameters and another constructor with an int parameter. Therefore, we can create an object of this class by using the constructor with the int parameter and passing the desired value for the parameter. The other options are incorrect because they either do not use the correct constructor or have incorrect syntax.

    Rate this question:

  • 20. 

    Sta od ponudjenih odgovora predstavlja ispravan konstruktor za klasu Radnik?

    • A.

      Radnik (Radnik r) { }

    • B.

      Radnik newRadnik() { }

    • C.

      Static void Radnik() { }

    • D.

      Radnik () { }

    • E.

      Void Radnik () { }

    Correct Answer(s)
    A. Radnik (Radnik r) { }
    D. Radnik () { }
    Explanation
    The correct answers for the given question are "Radnik (Radnik r) { }" and "Radnik () { }". These are the correct constructors for the class "Radnik". The first constructor takes an object of type "Radnik" as a parameter, which allows for creating a new object based on an existing one. The second constructor is a default constructor with no parameters, which allows for creating a new object without any initial values.

    Rate this question:

  • 21. 

    Ako postoji  statican metod test unutar klase ispit, na koji nacin se taj metod poziva  u programu?

    • A.

      Metod se poziva naredbom ispit.test{}, gde je ispit objekat nastao kao instanca klase ispit

    • B.

      Metod se poziva naredbom test(ispit), gde je Ispit ime klase, a test ime metoda

    • C.

      Metod se poziva naredbom Ispit.test(), bez potrebe da se prvo instancira objekat klase ispit

    • D.

      Metod se poziva naredbom ispit(test), gde je ispit ime klase, a test ime modela

    Correct Answer
    C. Metod se poziva naredbom Ispit.test(), bez potrebe da se prvo instancira objekat klase ispit
    Explanation
    The correct answer is "Metod se poziva naredbom Ispit.test(), bez potrebe da se prvo instancira objekat klase ispit." This means that the method can be called directly using the class name followed by the method name, without the need to create an instance of the class.

    Rate this question:

  • 22. 

    Sta se radi sa objektom koji vise nije potreban u programu?

    • A.

      Automatski se uklanja u javi procedurom Garbage Collection

    • B.

      Rucno se uklanja oslobadjenjem rezervisanog prostora

    • C.

      Ne uklanja se, vec ce prilikom sledeceg restartovanja racunara sva memorija biti ociscena

    Correct Answer
    A. Automatski se uklanja u javi procedurom Garbage Collection
    Explanation
    In Java, objects that are no longer needed in the program are automatically removed by the Garbage Collection process. This process identifies and collects objects that are no longer referenced by any part of the program, freeing up the memory allocated to those objects. This automated process helps in managing memory efficiently and eliminates the need for manual removal of objects.

    Rate this question:

  • 23. 

    Ako class Zivotinja {  } class Ljubimac extends Zivotinja {} public class Test {    public static void main(String[] args) {        Ljubimac lj = new Ljubimac();        Zivotinja z = new Zivotinja();        ubacen kod      } } KOje od sledecih komandi se mogu ubaciti na oznaceno mesto?

    • A.

      Ljubimac a = new Zivotinja();

    • B.

      Ljubimac a1 = z;

    • C.

      Ljubimac a1 = lj;

    • D.

      Zivotinja z1 = new Ljubimac();

    • E.

      Zivotinja z2 = lj;

    Correct Answer(s)
    C. Ljubimac a1 = lj;
    D. Zivotinja z1 = new Ljubimac();
    E. Zivotinja z2 = lj;
    Explanation
    The correct answers are "Ljubimac a1 = lj;", "Zivotinja z1 = new Ljubimac();", and "Zivotinja z2 = lj;". These statements are valid because they involve creating objects of the appropriate classes and assigning them to variables of compatible types. "Ljubimac a1 = lj;" is valid because a Ljubimac object can be assigned to a Ljubimac variable. "Zivotinja z1 = new Ljubimac();" is valid because a Ljubimac object can be assigned to a Zivotinja variable. "Zivotinja z2 = lj;" is valid because a Ljubimac object can be assigned to a Zivotinja variable.

    Rate this question:

  • 24. 

    Sta ce na standardnom izlazu ispisati sledeci kod? class A {      private int i;      protected int j;      A() {           i=1;           j=2;      } } public class Test {       public static void main(String[] args) {             A a1 = new A();             B b1 = new A();            System.out.println(a1.equals(a2));       } }

    • A.

      True

    • B.

      Greska prilikom kompajliranja

    • C.

      False

    Correct Answer
    B. Greska prilikom kompajliranja
    Explanation
    The code will not compile because the class A does not have a declaration for class B. Therefore, the line "B b1 = new A();" will cause a compilation error.

    Rate this question:

  • 25. 

    Koje od navedenih tvrdnji su tacne za apstraktne klase:

    • A.

      Apstraktna klasa mora imati jednu ili vise apstraktnih metoda

    • B.

      Apstraktna klasa moze biti definisana sa modifikatorom final u zaglavlju klase

    • C.

      Apstraktna klasa moze sadrzati main metodu

    • D.

      Apstraktna klasa moze imati satitcke metode

    • E.

      Apstraktna klasa moze implementirati interfejs

    Correct Answer(s)
    A. Apstraktna klasa mora imati jednu ili vise apstraktnih metoda
    C. Apstraktna klasa moze sadrzati main metodu
    D. Apstraktna klasa moze imati satitcke metode
    E. Apstraktna klasa moze implementirati interfejs
    Explanation
    An abstract class must have one or more abstract methods. An abstract class can contain a main method. An abstract class can have static methods. An abstract class can implement an interface. However, an abstract class cannot be defined with the final modifier in the class header.

    Rate this question:

  • 26. 

    Promenljive tipa apstraktne klase mogu pokazivati na koje objekte?

    • A.

      Iskljucivo na objekte klasa izvedenih iz te apstraktne klase

    • B.

      Na objekte te konkretne apstraktne klase i na objekte klasa izvedenih iz te apstraktne klase

    • C.

      Na objekte te konkretne apstraktne klase

    Correct Answer
    B. Na objekte te konkretne apstraktne klase i na objekte klasa izvedenih iz te apstraktne klase
    Explanation
    Variables of an abstract class type can point to objects of both the specific abstract class and objects of classes derived from that abstract class.

    Rate this question:

  • 27. 

    _______ postoje u programu klasa Vozilo i klasa Automobil izvedena iz klase Vozilo: clasas Vozilo { ..... } class Automobil extends Vozilo { .... } Da li je dozvoljeno napisati sledece u main metodi: Automobil a = new Automobil(); Vozilo v = a; Automobil b = v;

    • A.

      Nije dozvoljeno promenljiboj v dodeliti objekat tipa Automobil

    • B.

      Da, dozvoljeno je, automatski se vrse odgovarajuce konverzije

    • C.

      Nije dozvoljeno promenljivoj b koja je tipa Automobil dodeliti objekat tipa Vozilo bez eksplicitne konverzije

    Correct Answer
    C. Nije dozvoljeno promenljivoj b koja je tipa Automobil dodeliti objekat tipa Vozilo bez eksplicitne konverzije
    Explanation
    The given code snippet is attempting to assign an object of type Vozilo to a variable of type Automobil without explicit type conversion. In Java, when assigning objects to variables of different types, explicit type conversion is required if the assignment is not directly compatible. In this case, since Vozilo is the superclass of Automobil, the assignment from Automobil to Vozilo is allowed. However, the assignment from Vozilo to Automobil is not allowed without explicit type conversion. Therefore, it is not allowed to assign an object of type Vozilo to a variable of type Automobil without explicit type conversion.

    Rate this question:

  • 28. 

    Kako se klasa definise kao apstraktna?

    • A.

      Ubacivanjem kljucne reci abstract u zaglavlje klase

    • B.

      Dodavanjem kljucne reci abstract ispred imena nedefinisanih metoda, bez dodavanja bilo cega u zaglavlje klase

    • C.

      Ubacivanjem kljucne reci final u zaglavlje klase

    • D.

      Ne mora se eksplicitno definisati vec se podrazumeva ukoliko postoje metode koje nisu definisane

    • E.

      Ubacivanjem kljucne reci volatile u zaglavlje klase

    Correct Answer
    A. Ubacivanjem kljucne reci abstract u zaglavlje klase
    Explanation
    The correct answer is "Ubacivanjem kljucne reci abstract u zaglavlje klase" (By inserting the keyword abstract in the class header). This is because when the abstract keyword is used in the class header, it indicates that the class is abstract. An abstract class is a class that cannot be instantiated and is meant to be subclassed. It can contain abstract methods, which are methods without a body, and concrete methods with implementations.

    Rate this question:

  • 29. 

    Klasa A je definisana na sledeci nacin: abstract class A{} Sta je rezultat sledeceg koda? public class Test {   public static void main(String[] args) {        A a = new A();   } }

    • A.

      Greska prilikom prevodjenja programa, ne postoji konstruktor za klasu A

    • B.

      Kreiran je objekat tipa A

    • C.

      Greska prilikom prevodjenja programa, ne moze se instancirati apstraktna klasa

    Correct Answer
    C. Greska prilikom prevodjenja programa, ne moze se instancirati apstraktna klasa
    Explanation
    The correct answer is "Greska prilikom prevodjenja programa, ne moze se instancirati apstraktna klasa". This is because class A is defined as an abstract class, which means it cannot be instantiated directly. Abstract classes are meant to be extended by other classes, and objects can only be created from concrete subclasses of the abstract class. Therefore, attempting to create an object of type A will result in a compilation error.

    Rate this question:

  • 30. 

    Data je definicija klase Student: class Student {      private String name;      public String getName() { return name; }      public void setName(String name) { this.name = name; } } Sta ce biti ispisano na standardnom izlazu nakon izvrsenja sledeveg koda? class Test {      public static void main(String args[])      {            Student student = new Student();            student.setName("Bob");            Student studentClone = student;            studentClone.setName("Alice");            System.out.println(student.getName());       } }

    • A.

      Bob

    • B.

      Alice

    • C.

      Bice bacen sistemski izuzetak prilikom izvrsenja naredbe u trecoj liniji koda, jer u klasi Student nije definisan kopirajuci konstruktor

    Correct Answer
    B. Alice
    Explanation
    The code creates an instance of the Student class and sets its name to "Bob". Then, a reference variable studentClone is created and assigned the same memory address as student. When the name of studentClone is changed to "Alice", it also changes the name of the original student object. Therefore, when the code prints the name of the student object, it will be "Alice".

    Rate this question:

  • 31. 

    Sta ce na standardnom izlazu ispisati sledeci kod? class Student{     private String ime;     private String jmbg;     private int godinaUpisa;     public Student(String ime, String jmbg, int godinaUpisa) {           this.ime = ime;           this.jmbg = jmbg;           this.godinaUpisa = godinaUpisa;     }     public Student(String ime, String jmbg) {          this(ime, jmbg, 2018);     }    public void ispisi() {          System.out.println("Ime:  " +ime+ ", jmbg: " +jmbg+ ", godina upisa: " +godinaUpisa);    } } public class Test {     public static void main(String[] args) {          Student a = new Student("Pera", "25252525012501");          a.ispisi();     } }

    • A.

      Ime: Pera, jmbg: 25252525012501, godina upisa: 2018

    • B.

      Ime: Pera, jmbg: 25252525012501, godina upisa: 0

    • C.

      Program se nece kompajlirati posto se poziva konstruktor unutar drugog konstruktora

    • D.

      Program se nece kompajlirati posto nije prosledjena godina upisa

    Correct Answer
    A. Ime: Pera, jmbg: 25252525012501, godina upisa: 2018
    Explanation
    The code creates an instance of the Student class with the name "Pera" and the JMBG "25252525012501". The constructor used is the one that takes in the name, JMBG, and year of enrollment as parameters. Since the year of enrollment is not provided, the default value of 2018 is used. The ispisi() method is then called on the created instance, which prints out the name, JMBG, and year of enrollment as "Ime: Pera, jmbg: 25252525012501, godina upisa: 2018".

    Rate this question:

  • 32. 

    Ako zelimo da omogucimo koriscenje  objekta nase klase kao da je tekstualni podatak tipa String, potrebno je da definisemo sledeci metod u nasoj klasi

    • A.

      ToString

    • B.

      ToStringed

    • C.

      OfString

    • D.

      AsString

    • E.

      AsString  

    Correct Answer
    A. ToString
    Explanation
    The correct answer is "toString". In order to enable the use of an object of our class as if it were a String data type, we need to define the toString method in our class. This method is used to convert an object to its string representation, allowing it to be used as a String.

    Rate this question:

  • 33. 

    Koliko konstrukrora moze imati klasa?

    • A.

      Klasa moze imati 1 ili vise konstruktora, ali svi moraju imati razlicite potpise

    • B.

      Klasa moze imati 0 ili vise konstruktoa, ali svi moraju imati razlicite potpise

    • C.

      Klasa ne moze imati konstruktore

    • D.

      Klasa moze imati 1 konstruktor

    Correct Answer
    A. Klasa moze imati 1 ili vise konstruktora, ali svi moraju imati razlicite potpise
    Explanation
    The correct answer states that a class can have one or more constructors, but all of them must have different signatures. This means that a class can have multiple ways of being instantiated, each with different parameters. The requirement for different signatures ensures that the constructors can be differentiated and called appropriately based on the arguments provided.

    Rate this question:

  • 34. 

    Koja klasa se nalazi na vrhu hijerarhije klasa u javi?

    • A.

      Object

    • B.

      Structure

    • C.

      Super

    • D.

      Generic

    • E.

      Base

    Correct Answer
    A. Object
    Explanation
    The correct answer is "Object". In Java, the Object class is at the top of the class hierarchy. This means that all other classes in Java are subclasses of the Object class, either directly or indirectly. The Object class provides common methods and behaviors that are inherited by all other classes, such as toString(), equals(), and hashCode(). Therefore, Object is the most general and fundamental class in Java.

    Rate this question:

  • 35. 

    Enkapsulacija je vazan objektno orijentisani princip, za koji vaze:

    • A.

      Pristup vrednostima polja klase iz drugih klasa treba omoguciti samo preko javnih metoda

    • B.

      Otkrivaju se implementacioni detalji klase

    • C.

      Dozvoljava se direktan pristup objektnim poljima klase

    • D.

      Sva polja (i interne metode) se zasticeni unutar caure klase i mogu se menjati samo na kontrolisan nacin

    • E.

      Sva objektna polja klase treba da budu sakrivena

    • F.

      Nije moguce promeniti internu implementaciju klase bez posledica na programe koji je koriste

    Correct Answer(s)
    A. Pristup vrednostima polja klase iz drugih klasa treba omoguciti samo preko javnih metoda
    D. Sva polja (i interne metode) se zasticeni unutar caure klase i mogu se menjati samo na kontrolisan nacin
    E. Sva objektna polja klase treba da budu sakrivena
    Explanation
    The correct answer states that encapsulation is an important object-oriented principle that involves allowing access to the values of class fields only through public methods, protecting all fields and internal methods within the class, allowing them to be modified only in a controlled manner, and hiding all object fields of the class. This ensures that the internal implementation of the class cannot be changed without affecting the programs that use it.

    Rate this question:

  • 36. 

    Dinamicko vezivanje se obavlja po kom jednostavnom pravilu?

    • A.

      Nadjacan metod koji se poziva za neku klasnu promenljivu zavisi od deklarisanog tipa objekta na koji ukazuje promenljiva, bez obzira na stvarni tip

    • B.

      Nadjacan metod koji se poziva za neku klasnu promenljivu zavisi od stvarnog tipa objekta na koji ukazuje promenljiva, bez obzira na deklarisan tip

    • C.

      Koja se verzija preopterecene metode zapravo poziva se odredjuje na osnovu liste argumenata poziva

    Correct Answer
    B. Nadjacan metod koji se poziva za neku klasnu promenljivu zavisi od stvarnog tipa objekta na koji ukazuje promenljiva, bez obzira na deklarisan tip
    Explanation
    Dynamic binding refers to the process of determining which overridden method will be called for a class variable. In dynamic binding, the method that is called depends on the actual type of the object that the variable points to, regardless of the declared type of the variable. Therefore, the correct answer states that the overridden method that is called for a class variable depends on the actual type of the object it points to, regardless of the declared type.

    Rate this question:

  • 37. 

    Kod nasledjivanja klasa, kada nova klasa prosiruje postojecu klasu, za novu klasu vazi:

    • A.

      Nasledjuje samo zasticena (protected) polja i metode postojece klase

    • B.

      Nasledjuje sva polja i metode postojece klase

    • C.

      Nasledjuje samo sva polja postojece klase

    • D.

      Nasledjuje samo javna polja i javne metode postojece klase

    • E.

      Nasledjuje samo sve metode postojece klase

    Correct Answer
    B. Nasledjuje sva polja i metode postojece klase
    Explanation
    When a new class extends an existing class in inheritance, the new class inherits all the fields and methods of the existing class. This means that the new class can access and use all the variables and functions that are defined in the existing class. There is no restriction on the visibility of the fields and methods being inherited, so both protected and public fields and methods are inherited by the new class. However, private fields and methods are not inherited. Therefore, the correct answer is "Nasledjuje sva polja i metode postojece klase" which translates to "It inherits all the fields and methods of the existing class".

    Rate this question:

  • 38. 

    Kako se naziva proces definisanja vise od jedne metode sa istim  imenom unutar iste klase?

    • A.

      Preopterecenje metoda (overload)

    • B.

      Nije uopste dozvoljeno u programskom jeziku Java

    • C.

      Nadjacavanje metoda (override)

    Correct Answer
    A. Preopterecenje metoda (overload)
    Explanation
    The correct answer is "Preopterecenje metoda (overload)". This term refers to the process of defining multiple methods with the same name but different parameters within the same class. Overloading allows for more flexibility and versatility in programming, as it enables the same method name to be used for different purposes based on the input parameters. This helps to improve code readability and maintainability.

    Rate this question:

  • 39. 

    U Javi, polimorfizam se manifestuje kroz:

    • A.

      Enkapsulaciju

    • B.

      Princip podtipa

    • C.

      Staticke metode, koje se koriste bez konkretne instance objekta nad kojim se radi

    • D.

      Preopterecenje i nadjacavanje metoda

    Correct Answer(s)
    B. Princip podtipa
    D. Preopterecenje i nadjacavanje metoda
    Explanation
    Polimorfizam se manifestuje kroz princip podtipa, preopterećenje i nadjačavanje metoda. Princip podtipa se odnosi na mogućnost korišćenja objekata izvedenih klasa kao objekata baznih klasa. Preopterećenje metoda se odnosi na mogućnost definisanja više metoda sa istim imenom, ali sa različitim parametrima. Nadjačavanje metoda se odnosi na mogućnost da izvedena klasa implementira metodu koju je već definisala bazna klasa, ali sa drugačijom implementacijom.

    Rate this question:

  • 40. 

    Sta ce na standardnom izlazu ispisati sledeci kod? class exception_handling;? {      public static void main(String args[])      {            try           {                  int a, b;                  b = 0;                  a = 5 / b;                  System.out.print("A");           }          catch(ArithmeticException e)          {                System.out.print("B");            }     } }

    • A.

      False

    • B.

      Error: division by zero

    • C.

      B

    • D.

      A

    Correct Answer
    C. B
    Explanation
    The correct answer is B because when the code is executed, an ArithmeticException is thrown due to the division by zero (5/0). This exception is caught by the catch block that specifically handles ArithmeticException. Therefore, "B" is printed on the standard output.

    Rate this question:

  • 41. 

    Da li su sledece definicije klase u Javi ispravne: abstract class A { } class B extends A { } final class C extends B { } final class D extends C { }

    • A.

      Klasa D je neispravno definisana zato sto nasledjuje klasu C koja je final

    • B.

      Svim klasama nedostaje kljucna rec public na pocetku

    • C.

      Sve klase su pogresno definisane

    • D.

      Sve klase su isparavno definisane

    • E.

      Klasa B je neispravno definisana zato sto nasledjuje klasu A koja je apstraktna

    • F.

      Klasa B je neispravno definisana zato sto nasledjuje klasu A koja je apstraktna

    Correct Answer
    A. Klasa D je neispravno definisana zato sto nasledjuje klasu C koja je final
    Explanation
    The class D is incorrectly defined because it extends the class C which is final.

    Rate this question:

  • 42. 

    Koje od navedenih tvrdnji su tacne za staticke metode?

    • A.

      Staticke metode se mogu pozivati u programu nezavisno od konstruisanih objekata njihove klase

    • B.

      Staticke metode se mogu pozivati u programu samo u slucaju da postoji konkretni objekat sa kojim se radi

    • C.

      Staticke metode mogu pristupati samo statickim poljima

    • D.

      Staticke metode mogu pristupati samo objektnim poljima

    Correct Answer(s)
    A. Staticke metode se mogu pozivati u programu nezavisno od konstruisanih objekata njihove klase
    C. Staticke metode mogu pristupati samo statickim poljima
    Explanation
    Static methods can be called in a program independently of the objects of their class, meaning that they can be accessed without creating an instance of the class. Additionally, static methods can only access static fields, as they do not have access to object-specific fields.

    Rate this question:

  • 43. 

    Za pristup clanovima bazne klase koji su zaklonjeni clanovima izvedene klase, korsiti se kljucna rec:

    • A.

      Super

    • B.

      Base

    • C.

      Override

    • D.

      Parent

    Correct Answer
    A. Super
    Explanation
    The correct answer is "super". In object-oriented programming, the "super" keyword is used to access members of the base class that are hidden by members of the derived class. It allows the derived class to call the overridden method or constructor of the base class. By using "super", the derived class can access and use the functionality of the base class while still being able to override or extend it.

    Rate this question:

  • 44. 

    Definisana je klasa A na sledeci nacin: class A {      int a;      int b;      public A (int a, int b) {           this.a = a;           this.b = b;      }      public boolean equal (A second)      {           if(this.a==second.a && this.b==second.b)                 return true;           else                 return false;        } } Sta je rezultat izvrsenja sledeceg koda: A a1 = new A(2,1); A a2 = new A(2,1); if(a1==a2) System.out.println("Sa==su jednaki."); else System.out.println("Sa==nisu jednaki."); if(a1.equal(a2)) System.out.println("Sa equal su jednaki."); else System.out.println("Sa equal nisu jednaki.");

    • A.

      Sa==nisu jednaki. Sa equal nisu jednaki.

    • B.

      Sa==su jednaki. Sa equal su jednaki.

    • C.

      Sa==nisu jedanki. Sa equal su jednaki.

    • D.

      Greska pri kompajliranju

    Correct Answer
    C. Sa==nisu jedanki. Sa equal su jednaki.
    Explanation
    The code creates two objects of class A, a1 and a2, with the same values for the variables a and b. However, when comparing the objects using the "==" operator, it checks if the two object references are pointing to the same memory location, which is not the case here. Therefore, the condition "a1==a2" evaluates to false and the statement "Sa==nisu jednaki." is printed.

    On the other hand, when using the "equal" method defined in class A, it compares the values of the variables a and b of the two objects. Since the values are the same, the condition "a1.equal(a2)" evaluates to true and the statement "Sa equal su jednaki." is printed.

    Rate this question:

  • 45. 

    Koje od sledecih tvrdnji su tacne za nasledjivanje klasa:

    • A.

      Clanovi bazne klase deklarisani modifikatorom protected nisu dostupni u izvedenim klasama koje se nalaze izvan paketa

    • B.

      Nije moguce nadjacati (override) metodu koja je u baznoj klasi deklarisana kao private

    • C.

      Metode bazne klase deklarisane sa modifikatorom private se ponasaju identicno kao da su definisane kao final

    • D.

      Metode bazne klase deklarisane sa modifikatorom protected se ponasaju identicno kao da su definisane kao final

    • E.

      Clanovi bazne klase sa modifikatorom protected su dostupni u kodu paketa, i u svim klasama koje su izvedene iz date bazne klase (cak i ukoliko su izvan tog paketa)

    Correct Answer(s)
    A. Clanovi bazne klase deklarisani modifikatorom protected nisu dostupni u izvedenim klasama koje se nalaze izvan paketa
    B. Nije moguce nadjacati (override) metodu koja je u baznoj klasi deklarisana kao private
    C. Metode bazne klase deklarisane sa modifikatorom private se ponasaju identicno kao da su definisane kao final
    Explanation
    The first statement is correct because members of a base class declared with the protected modifier are not accessible in derived classes outside of the package. The second statement is correct because it is not possible to override a method that is declared as private in the base class. The third statement is incorrect because methods in the base class declared with the private modifier do not behave the same as if they were defined as final. The fourth statement is incorrect because methods in the base class declared with the protected modifier do not behave the same as if they were defined as final. The fifth statement is correct because members of a base class with the protected modifier are accessible in the package code and in all classes that are derived from the base class, even if they are outside of that package.

    Rate this question:

  • 46. 

    Sta ce na standardnom izlazu ispisati sledeci kod: class box {            int width;            int height;            int lenght; } class mainclass {        public static void main(String args[]) {               box obj = new box();               obj.height = 1;               obj.lenght = 2;               obj.width = 1;                  System.out.println(obj.toString());         } }

    • A.

      Prevodjenje programskog koda nece biti moguc

    • B.

      Height=1, lenght=2, width=1

    • C.

      1 2 1

    • D.

      ImeKlase@hashcode

    Correct Answer
    D. ImeKlase@hashcode
    Explanation
    The code creates an object of the "box" class and assigns values to its height, length, and width attributes. Then, it uses the toString() method to print the object. Since the "box" class does not have a custom implementation of the toString() method, the default implementation is used, which prints the class name followed by the object's hash code. Therefore, the output will be "imeKlase@hashcode".

    Rate this question:

  • 47. 

    Da li je u Javi dozvoljeno da catch blok bude prazan? try { ... } catch (Exception e) { }

    • A.

      Ne, nije dozvoljeno, obavezno se mora odstampati poruka greske dohvatanjem e.getMessage()

    • B.

      Ne, nije dozvoljeno, unutar catch bloka se mora dohvatiti objekat greske e i proveriti koji je konkretni tip greske u pitanju, i uraditi odgovarajuci oporavak od greske

    • C.

      Ne, nije dozvoljeno,, mora postojati bar jedna instrukcija unutar catch bloka

    • D.

      Da, dozvoljeno je, ali nije dobra praksa, jer je u tom bloku potrebno izvrsiti oporavak od greske

    Correct Answer
    D. Da, dozvoljeno je, ali nije dobra praksa, jer je u tom bloku potrebno izvrsiti oporavak od greske
    Explanation
    It is allowed to have an empty catch block in Java, but it is not considered good practice because the purpose of the catch block is to handle and recover from the exception. Without any code inside the catch block, the exception will not be handled or recovered from, which can lead to unexpected behavior or errors in the program. It is recommended to at least print the error message by using e.getMessage() to provide some information about the exception.

    Rate this question:

  • 48. 

    Sta ce na standardnom izlazu ispisati sledeci kod? final class A    {         int i;     } class B extends A {          int j;          void display(){                  System.out.println(j + " " + i);          } } class inheritance {          public static void main(String args[])         {                 B obj = new B();                 obj.dispaly();          } }

    • A.

      Program se nece kompajlirati zato sto nisu dodeljene vrednosti promenljivama i i j

    • B.

      0 0

    • C.

      Program se nece kompajlirati zato sto nisu napravljeni geter i seter za atribut i

    • D.

      Program se nece kompajlirati zato sto klasa B nasledjuje final klasu A

    Correct Answer
    D. Program se nece kompajlirati zato sto klasa B nasledjuje final klasu A
    Explanation
    The program will not compile because class B is trying to inherit from a final class A.

    Rate this question:

  • 49. 

    Class Osoba {     private String ime;     private String jmbg;       public Osoba(String ime, String jmbg) {           this.ime = ime;           this.jmbg = jmbg;     } class Student extends Osoba {       private int godinaUpisa;       public Student(String ime, String jmbg, int godinaUpisa) {               this.ime = ime;            this.jmbg = jmbg;            this godinaUpisa = godinaUpisa;     }    public void ispisi() {          System.out.println("Ime:  " + ime + ", jmbg: " + jmbg + ", godina upisa: " + godinaUpisa);    } } public class Test {     public static void main(String[] args) {          Student a = new Student("Pera", "25252525012501", 2018);          a.ispisi();     } }

    • A.

      Program se nece kompajlirati, greska je u metodi ispisi klase Osoba

    • B.

      Ime: Pera. jmbg: 25252525012501 , godina upisa: 2018

    • C.

      Program se nece kompajlirati, greska je u konstruktoru klase Student

    • D.

      Program se nece kompajlirati, greska je u konstruktoru klase Osoba

    • E.

      Program se nece kompajlirati, greska je u metodi ispisi klase Student

    Correct Answer(s)
    C. Program se nece kompajlirati, greska je u konstruktoru klase Student
    E. Program se nece kompajlirati, greska je u metodi ispisi klase Student
    Explanation
    The correct answer is "Program se nece kompajlirati, greska je u konstruktoru klase Student". This is because in the constructor of the Student class, there is a syntax error where the keyword "this" is missing before the variable "godinaUpisa". This causes a compilation error and the program will not be able to run. Additionally, the answer also states that there is an error in the method "ispisi" of the Student class, but this is incorrect as there is no error in that method.

    Rate this question:

  • 50. 

    Posmatra se metoda: public int podeli (int a, int b) {    if(b==0) throw new ArithmeticException ("Pokusaj deljenje sa nulom");    return a/b; } Da li je metoda ispravno definisana, odnosno  da li ce moci  da se kompajlira?

    • A.

      Metoda nije ispravno definisana, posto fali klauzula u zaglavlju metoda

    • B.

      Metoda je ispravno definisana

    • C.

      Metoda nije ispravno definisana, posto je u ovom slucaju potrebno izbaciti izuzetak tipa IlegalArgumetnException

    Correct Answer
    C. Metoda nije ispravno definisana, posto je u ovom slucaju potrebno izbaciti izuzetak tipa IlegalArgumetnException
    Explanation
    The given method is not correctly defined because it is missing a clause in the method header to indicate that it can throw an exception of type IllegalArgumentException.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 16, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 06, 2018
    Quiz Created by
    Akacadjo
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.