1 777
Subscribers
-124 hours
-177 days
-3330 days
Posts Archive
1 777
LESSON 15: ๐File Class in java๐
๐The File class is an abstract representation of file and directory pathname. A pathname can be either absolute or relative.
๐Once you have File object in hand, then there is a list of helper methods which can be used to manipulate the files.
Eg: public String getName()
public String getParent()
public File getParentFile()
public String getPath()
public boolean isAbsolute() ... and etc.
import java.io.*;
public class LearnTcode {
public static void main(String[] args) {
try {
File file = new File("learnTocode.txt");
if (file.createNewFile()) {
System.out.println("Join our channel");
} else {
System.out.println("File already exists.");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
//output is: Join our channel1 777
What will be the output of the following program?
public class King {
public static void main(String[] args) {
King k = new King();
Elephant e = k.new Elephant();
System.out.print("Output = ");
System.out.print(e.step2(2, 3));
}
interface Queen {
float step2(int low, int high);
}
interface Pawn {
float step3(int a, int b, int c);
}
abstract class Knight implements Queen, Pawn {
}
class Elephant implements Queen {
public float step2(int x, int y) {
return 2;
}
}
}
//
1 777
Q!: Which two of the following are legal declarations for non-nested interfaces?
1 777
LESSON 14: ABSTRACTION and INTERFACES
๐ฑ Abstraction is the property by virtue of which only the essential details are displayed to the user. The trivial or the non-essential units are not displayed to the user. Ex: A car is viewed as a car rather than its individual components
โณ๏ธAn Interface in Java programming language is defined as an abstract type used to specify the behavior of a class. An interface in Java is a blueprint of a class. A Java interface contains static constants and abstract methods.
โ๏ธWhy do we use an Interface?โ
> It is used to achieve total abstraction.
Since java does not support multiple inheritances in the case of class, by using an interface it can achieve multiple inheritances.
> It is also used to achieve loose coupling.
> Interfaces are used to implement abstraction. So the question arises why use interfaces when we have abstract classes?
1 777
Qm: which access modifier can be used to access different packages sub-classes created using inheritance?
1 777
LESSON 13: INHERITANCE
โ๏ธInheritance is one of the basic concept in object
orientation in which a new class is created by
absorbing an existing classโs members and
embellishing them with new or modified capabilities.
โ
The existing class is called the superclass, and the
new class is the subclass.
Syntax for inheritance
class SubClassName extends SuperClassName{};
Why And When To Use "Inheritance"?
- It is useful for code reusability: reuse attributes and methods of an existing class when you create a new class.
Let's explore by using sample code:-
class Vehicle {
protected String brand = "Ford"; // Vehicle attribute
public void honk() { // Vehicle method
System.out.println("Tuut, tuut!");
}
}
class Car extends Vehicle {
private String modelName = "Mustang"; // Car attribute
public static void main(String[] args) {
// Create a myCar object
Car myCar = new Car();
// Call the honk() method (from the Vehicle class) on the myCar object
myCar.honk();
// Display the value of the brand attribute (from the Vehicle class) and the value of the modelName from the Car class
System.out.println(myCar.brand + " " + myCar.modelName);
}
}
"thanks all!๐"1 777
Q: The ability to define more than one function with the same name is calledโ-;
1 777
LESSON 12: POLYMORPHISM
The word polymorphism means having many forms. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form.
Types of polymorphism
In Java , polymorphism is mainly divided into two types:
i.Compile-time Polymorphism
๐This type of polymorphism is achieved by function overloading or operator overloading. But Java doesnโt support the Operator Overloading.
ii.Runtime Polymorphism
โค๏ธโ๐ฅIt is a process in which a function call to the overridden method is resolved at Runtime. This type of polymorphism is achieved by Method Overriding.
>๐ Java program to demostrate polymorphism
class Parent {
// Method of parent class
void Print()
{
// Print statement
System.out.println("parent class");
}
}
// Helper class
class subclass2 extends Parent {
// Method
void Print()
{
// Print statement
System.out.println("subclass2");
}
}
// Class 4
// Main class
class GFG {
// Main driver method
public static void main(String[] args)
{
// Creating object of class 1
Parent a;
// Now we will be calling print methods
// inside main() method
a = new subclass1();
a.Print();
}
}1 777
Description: material for Python
Size: 4.2 MB
credit: Mohammed๐๐
๐@PROGRAMMINGLANGUAGES1
Available now! Telegram Research 2025 โ the year's key insights 
