Lecture 3 Flashcards

1
Q

How do you create a class in Java

A

class NameofClass{
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Chaterstics of a class

A

Constructors always have the same name as the class.
Constructors don’t have a return type.
Constructor is a block of code that can be used to initializes the newly created object.
A constructor resembles an instance method in java but it’s not a method as it doesn’t have a return type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give an example of a constructor syntax

A

class NameofClass{
NameofClass();
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Mention types of constructor

A
  1. Default constructor
    If you do not implement any constructor in your class, Java compiler inserts a default constructor into your code on your behalf at compilation time.
    This constructor is known as default constructor.
  2. no-arg constructor:
    Constructor with no arguments is known as no-arg constructor. The signature is same as default constructor, however body can have any code unlike default constructor where the body of the constructor is empty.
  3. Parameterized constructor
    Constructor with arguments(or you can say parameters) is known as Parameterized constructor.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is constructor overloading

A

Constructor overloading is a concept of having more than one constructor with different parameters so that every constructor can perform a different task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a method

A

A method is a collection or a block of statements that perform some specific task and return the result to the caller or not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is method of overloading

A

Method Overloading is a feature that allows a class to have multiple methods with the same name but with different number, sequence or type of parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Difference between constructor and methods

A

A Constructor is invoked implicitly by the system while a Method is invoked by the programmer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Difference between classes and interface

A

In Java, a class is a blueprint or template for creating objects. It defines the properties (fields or attributes) and behaviors (methods or functions) that all objects of that class will have.

On the other hand, an interface in Java defines a contract for classes to follow. It specifies a set of method signatures (without implementations) that any class implementing the interface must provide. Think of it as a promise that any class implementing the interface will provide certain functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

An example of interface and class

A

// Define the Animal interface
interface Animal {
void makeSound();
}

// Define the Dog class implementing the Animal interface
class Dog implements Animal {
@Override
public void makeSound() {
System.out.println(“Woof”);
}
}

// Define the Cat class implementing the Animal interface
class Cat implements Animal {
@Override
public void makeSound() {
System.out.println(“Meow”);
}
}

public class Main {
public static void main(String[] args) {
// Create objects of Dog and Cat
Dog myDog = new Dog();
Cat myCat = new Cat();

    // Call makeSound method on Dog and Cat objects
    myDog.makeSound(); // Output: Woof
    myCat.makeSound(); // Output: Meow
} }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe java.lang.Runnable

A

java.lang.Runnable is an interface that is to be implemented by a class whose instances are intended to be executed by a thread.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Major components of AWT

A

Containers
Canvases: It is a simple drawing interface
UI compoenets
Window construction components

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly