logo

Crowdly

CS102 - Object-Oriented Programming 1 F1 - S25

Шукаєте відповіді та рішення тестів для CS102 - Object-Oriented Programming 1 F1 - S25? Перегляньте нашу велику колекцію перевірених відповідей для CS102 - Object-Oriented Programming 1 F1 - S25 в moodle.medtech.tn.

Отримайте миттєвий доступ до точних відповідей та детальних пояснень для питань вашого курсу. Наша платформа, створена спільнотою, допомагає студентам досягати успіху!

In Java, each child class can have only one parent.

 

Переглянути це питання

What is the output of the following program?

  1. class  Parent{  
  2.    void PrintData() {  
  3.       System.out.println("method of parent class");  
  4.    }  
  5. }  
  6.   
  7. class Child extends Parent {  
  8.    void PrintData() {  
  9.       System.out.println("method of child class");  
  10.    }  
  11. }  
  12. class UpcastingExample{  
  13.    public static void main(String args[]) {  
  14.         
  15.       Parent obj1 = (Parent) new Child();  
  16.       Parent obj2 = (Parent) new Child();   
  17.       obj1.PrintData();  
  18.       obj2.PrintData();  
  19.    }  
  20. }  
0%
0%
0%
Переглянути це питання

What is the purpose of upcasting in Java? 

Переглянути це питання

What is the output of the following code snippet?

class Person{

String name;

Person(){

  System.out.println("In Person class");

  }

}

class Student extends Person{

Student(){

  System.out.println("In Student class");

  }

int id;

public static void main(String[] a){

Student ob=new Student(); //Line 1

ob.name="abc"; //Line 2

ob.id=123;}

}

 

Переглянути це питання

What is the output of this program

class Person{

String name;

Person(){

name="John";

}

}

class Employee extends Person{

int age;

Employee(){

age=34;

}

}

class Customer extends Person{

int salary;

Customer(int salary){

this.salary=salary;

name="Maddy";

}

public void displayDetails(){

System.out.println(name+age+salary);

}

}

class Account {

public static void main(String[] args) {

Customer c=new Customer(20000);

c.displayDetails();

}

}

Переглянути це питання

What is the output of the following program?

class SolarSystem {

}

class Earth extends SolarSystem {

}

class Mars extends SolarSystem {

}

public class Moon extends Earth {

public static void main(String args[])

{

SolarSystem s = new SolarSystem();

Earth e = new Earth();

Mars m = new Mars();

System.out.println(s instanceof SolarSystem);

System.out.println(e instanceof Earth);

System.out.println(m instanceof SolarSystem);

}

}

0%
0%
0%
Переглянути це питання

What is the output of the following program?

  1. class Parent {   
  2.     String name;   
  3.     
  4.     void showMessage()   

  5.     {   
  6.         System.out.println("Parent method is called");   
  7.     }   
  8. }   
  9. class Child extends Parent {   

  10.     int age;   
  11.     
  12.     @Override  

  13.     void showMessage()   
  14.     {   
  15.         System.out.println("Child method is called");   
  16.     }   
  17. }   
  18.     
  19. public class Downcasting{  
  20.     
  21.     public static void main(String[] args)   
  22.     {   
  23.         Parent p = new Child();  
  24.         p.name = "Adrian";  
  25.       
  26.         Child c = (Child)p;   
  27.         c.age = 18;   
  28.         System.out.println(c.name);   
  29.         System.out.println(c.age);   
  30.         c.showMessage();   
  31.     }   
  32. }  
Переглянути це питання

What is the output of the following program?

class Animal {

protected String name;

protected void display() {

System.out.println("I am an animal.");

}

}

class Dog extends Animal {

protected void display() {

System.out.println("I am a Dog");

}

public void getInfo() {

System.out.println("My name is " + name);

}

}

class Main {

public static void main(String[] args) {

// create an object of the subclass

Dog labrador = new Dog();

// access protected field and method

// using the object of subclass

labrador.name = "Rocky";

labrador.display();

labrador.getInfo();

}

}

0%
0%
Переглянути це питання

In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?

Переглянути це питання

What is the output of this program?

class A {

    int i;}

 

class B extends A {

        int j;

    void display() 

    {   super.i = j + 1;

        System.out.println(j + " " + i); }

}    

 

class inheritance {

    public static void main(String args[]) {

        B obj = new B();

       obj.i=1;

       obj.j=2;   

       obj.display(); }

}

Переглянути це питання

Хочете миттєвий доступ до всіх перевірених відповідей на moodle.medtech.tn?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!